• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************************
2   test_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 #include "TestClass.h"
18 #include "LeakCheck.h"
19 # if defined (EH_NEW_HEADERS)
20 #include <map>
21 # else
22 #include <multimap.h>
23 #include <map.h>
24 # endif
25 
26 #include "test_construct.h"
27 #include "test_assign_op.h"
28 #include "test_push_back.h"
29 #include "test_insert.h"
30 #include "test_push_front.h"
31 #include "ThrowCompare.h"
32 #include "test_insert.h"
33 
34 template <class K, class V, class Comp, class A>
35 inline multimap_tag
container_category(const EH_STD::__multimap__<K,V,Comp,A> &)36 container_category(const EH_STD::__multimap__<K,V,Comp, A>&)
37 {
38     return multimap_tag();
39 }
40 
41 template <class K, class V, class Comp, class A >
42 inline map_tag
container_category(const EH_STD::__map__<K,V,Comp,A> &)43 container_category(const EH_STD::__map__<K,V,Comp, A>&)
44 {
45     return map_tag();
46 }
47 
48 typedef EH_STD::__multimap__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMultiMap;
49 
test_multimap()50 void test_multimap()
51 {
52     TestMultiMap testMultiMap, testMultiMap2;
53 
54     const size_t mapSize = random_number(random_base);
55 
56     while ( testMultiMap.size() < mapSize )
57     {
58         TestMultiMap::value_type x;
59         testMultiMap.insert( x );
60         testMultiMap2.insert( TestMultiMap::value_type() );
61     }
62 
63     StrongCheck( testMultiMap, test_insert_value<TestMultiMap>(testMultiMap) );
64 
65     size_t insCnt = 1 + random_number(random_base);
66     TestMultiMap::value_type *insFirst = new TestMultiMap::value_type[insCnt];
67 
68     WeakCheck( testMultiMap, insert_range_tester(testMultiMap, insFirst, insFirst+insCnt) );
69 
70     ConstCheck( 0, test_construct_pointer_range<TestMultiMap>(insFirst, insFirst+insCnt) );
71     delete[] insFirst;
72 
73 
74     WeakCheck( testMultiMap, insert_range_tester(testMultiMap, testMultiMap2.begin(), testMultiMap2.end() ) );
75 
76 
77     ConstCheck( 0, test_default_construct<TestMultiMap>() );
78 
79     ConstCheck( 0, test_construct_iter_range<TestMultiMap>( testMultiMap2 ) );
80 
81     ConstCheck( testMultiMap, test_copy_construct<TestMultiMap>() );
82 
83     WeakCheck( testMultiMap, test_assign_op<TestMultiMap>( testMultiMap2 ) );
84 }
85 
86 typedef EH_STD::__map__<TestClass, TestClass, ThrowCompare, eh_allocator(TestClass) > TestMap;
87 
88 void CheckInvariant( const TestMap& m );
89 
CheckInvariant(const TestMap & m)90 void CheckInvariant( const TestMap& m )
91 {
92 //  assert( map.__rb_verify() );
93     size_t total = 0;
94     EH_DISTANCE( m.begin(), m.end(), total );
95     assert( m.size() == total );
96 }
97 
test_map()98 void test_map()
99 {
100     TestMap testMap, testMap2;
101 
102     const size_t mapSize = random_number(random_base);
103 
104     while ( testMap.size() < mapSize )
105     {
106         TestMap::value_type x;
107         testMap.insert( x );
108         testMap2.insert( TestMap::value_type() );
109     }
110 
111     StrongCheck( 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 
116     WeakCheck( testMap, insert_range_tester(testMap, insFirst, insFirst+insCnt) );
117 
118     ConstCheck( 0, test_construct_pointer_range<TestMap>(insFirst, insFirst+insCnt) );
119     delete[] insFirst;
120 
121     WeakCheck( testMap, insert_range_tester(testMap, testMap2.begin(), testMap2.end() ) );
122     ConstCheck( 0, test_default_construct<TestMap>() );
123     ConstCheck( 0, test_construct_iter_range<TestMap>( testMap2 ) );
124     ConstCheck( testMap, test_copy_construct<TestMap>() );
125     WeakCheck( testMap, test_assign_op<TestMap>( testMap2 ) );
126 }
127 
128