1*c2c66affSColin Finck //Has to be first for StackAllocator swap overload to be taken
2*c2c66affSColin Finck //into account (at least using GCC 4.0.1)
3*c2c66affSColin Finck #include "stack_allocator.h"
4*c2c66affSColin Finck
5*c2c66affSColin Finck #include <map>
6*c2c66affSColin Finck #include <algorithm>
7*c2c66affSColin Finck
8*c2c66affSColin Finck #include "cppunit/cppunit_proxy.h"
9*c2c66affSColin Finck
10*c2c66affSColin Finck #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
11*c2c66affSColin Finck using namespace std;
12*c2c66affSColin Finck #endif
13*c2c66affSColin Finck
14*c2c66affSColin Finck //
15*c2c66affSColin Finck // TestCase class
16*c2c66affSColin Finck //
17*c2c66affSColin Finck class MapTest : public CPPUNIT_NS::TestCase
18*c2c66affSColin Finck {
19*c2c66affSColin Finck CPPUNIT_TEST_SUITE(MapTest);
20*c2c66affSColin Finck CPPUNIT_TEST(map1);
21*c2c66affSColin Finck CPPUNIT_TEST(mmap1);
22*c2c66affSColin Finck CPPUNIT_TEST(mmap2);
23*c2c66affSColin Finck CPPUNIT_TEST(iterators);
24*c2c66affSColin Finck CPPUNIT_TEST(equal_range);
25*c2c66affSColin Finck CPPUNIT_TEST(allocator_with_state);
26*c2c66affSColin Finck #if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION)
27*c2c66affSColin Finck CPPUNIT_IGNORE;
28*c2c66affSColin Finck #endif
29*c2c66affSColin Finck CPPUNIT_TEST(template_methods);
30*c2c66affSColin Finck CPPUNIT_TEST_SUITE_END();
31*c2c66affSColin Finck
32*c2c66affSColin Finck protected:
33*c2c66affSColin Finck void map1();
34*c2c66affSColin Finck void mmap1();
35*c2c66affSColin Finck void mmap2();
36*c2c66affSColin Finck void iterators();
37*c2c66affSColin Finck void equal_range();
38*c2c66affSColin Finck void allocator_with_state();
39*c2c66affSColin Finck void template_methods();
40*c2c66affSColin Finck };
41*c2c66affSColin Finck
42*c2c66affSColin Finck CPPUNIT_TEST_SUITE_REGISTRATION(MapTest);
43*c2c66affSColin Finck
44*c2c66affSColin Finck //
45*c2c66affSColin Finck // tests implementation
46*c2c66affSColin Finck //
map1()47*c2c66affSColin Finck void MapTest::map1()
48*c2c66affSColin Finck {
49*c2c66affSColin Finck typedef map<char, int, less<char> > maptype;
50*c2c66affSColin Finck maptype m;
51*c2c66affSColin Finck // Store mappings between roman numerals and decimals.
52*c2c66affSColin Finck m['l'] = 50;
53*c2c66affSColin Finck m['x'] = 20; // Deliberate mistake.
54*c2c66affSColin Finck m['v'] = 5;
55*c2c66affSColin Finck m['i'] = 1;
56*c2c66affSColin Finck // cout << "m['x'] = " << m['x'] << endl;
57*c2c66affSColin Finck CPPUNIT_ASSERT( m['x']== 20 );
58*c2c66affSColin Finck m['x'] = 10; // Correct mistake.
59*c2c66affSColin Finck CPPUNIT_ASSERT( m['x']== 10 );
60*c2c66affSColin Finck CPPUNIT_ASSERT( m['z']== 0 );
61*c2c66affSColin Finck //cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
62*c2c66affSColin Finck CPPUNIT_ASSERT( m.count('z') == 1 );
63*c2c66affSColin Finck //cout << "m.count('z') = " << m.count('z') << endl;
64*c2c66affSColin Finck pair<maptype::iterator, bool> p = m.insert(pair<const char, int>('c', 100));
65*c2c66affSColin Finck CPPUNIT_ASSERT( p.second );
66*c2c66affSColin Finck CPPUNIT_ASSERT( p.first != m.end() );
67*c2c66affSColin Finck CPPUNIT_ASSERT( (*p.first).first == 'c' );
68*c2c66affSColin Finck CPPUNIT_ASSERT( (*p.first).second == 100 );
69*c2c66affSColin Finck
70*c2c66affSColin Finck p = m.insert(pair<const char, int>('c', 100));
71*c2c66affSColin Finck CPPUNIT_ASSERT( !p.second ); // already existing pair
72*c2c66affSColin Finck CPPUNIT_ASSERT( p.first != m.end() );
73*c2c66affSColin Finck CPPUNIT_ASSERT( (*p.first).first == 'c' );
74*c2c66affSColin Finck CPPUNIT_ASSERT( (*p.first).second == 100 );
75*c2c66affSColin Finck }
76*c2c66affSColin Finck
mmap1()77*c2c66affSColin Finck void MapTest::mmap1()
78*c2c66affSColin Finck {
79*c2c66affSColin Finck typedef multimap<char, int, less<char> > mmap;
80*c2c66affSColin Finck mmap m;
81*c2c66affSColin Finck CPPUNIT_ASSERT(m.count('X')==0);
82*c2c66affSColin Finck
83*c2c66affSColin Finck m.insert(pair<const char, int>('X', 10)); // Standard way.
84*c2c66affSColin Finck CPPUNIT_ASSERT(m.count('X')==1);
85*c2c66affSColin Finck
86*c2c66affSColin Finck m.insert(pair<const char, int>('X', 20)); // jbuck: standard way
87*c2c66affSColin Finck CPPUNIT_ASSERT(m.count('X')==2);
88*c2c66affSColin Finck
89*c2c66affSColin Finck m.insert(pair<const char, int>('Y', 32)); // jbuck: standard way
90*c2c66affSColin Finck mmap::iterator i = m.find('X'); // Find first match.
91*c2c66affSColin Finck #ifndef _STLP_CONST
92*c2c66affSColin Finck # define _STLP_CONST const
93*c2c66affSColin Finck #endif
94*c2c66affSColin Finck pair<_STLP_CONST char, int> p('X', 10);
95*c2c66affSColin Finck CPPUNIT_ASSERT(*i == p);
96*c2c66affSColin Finck CPPUNIT_ASSERT((*i).first == 'X');
97*c2c66affSColin Finck CPPUNIT_ASSERT((*i).second == 10);
98*c2c66affSColin Finck i++;
99*c2c66affSColin Finck CPPUNIT_ASSERT((*i).first == 'X');
100*c2c66affSColin Finck CPPUNIT_ASSERT((*i).second == 20);
101*c2c66affSColin Finck i++;
102*c2c66affSColin Finck CPPUNIT_ASSERT((*i).first == 'Y');
103*c2c66affSColin Finck CPPUNIT_ASSERT((*i).second == 32);
104*c2c66affSColin Finck i++;
105*c2c66affSColin Finck CPPUNIT_ASSERT(i == m.end());
106*c2c66affSColin Finck
107*c2c66affSColin Finck size_t count = m.erase('X');
108*c2c66affSColin Finck CPPUNIT_ASSERT(count==2);
109*c2c66affSColin Finck }
mmap2()110*c2c66affSColin Finck void MapTest::mmap2()
111*c2c66affSColin Finck {
112*c2c66affSColin Finck typedef pair<const int, char> pair_type;
113*c2c66affSColin Finck
114*c2c66affSColin Finck pair_type p1(3, 'c');
115*c2c66affSColin Finck pair_type p2(6, 'f');
116*c2c66affSColin Finck pair_type p3(1, 'a');
117*c2c66affSColin Finck pair_type p4(2, 'b');
118*c2c66affSColin Finck pair_type p5(3, 'x');
119*c2c66affSColin Finck pair_type p6(6, 'f');
120*c2c66affSColin Finck
121*c2c66affSColin Finck typedef multimap<int, char, less<int> > mmap;
122*c2c66affSColin Finck
123*c2c66affSColin Finck pair_type array [] = {
124*c2c66affSColin Finck p1,
125*c2c66affSColin Finck p2,
126*c2c66affSColin Finck p3,
127*c2c66affSColin Finck p4,
128*c2c66affSColin Finck p5,
129*c2c66affSColin Finck p6
130*c2c66affSColin Finck };
131*c2c66affSColin Finck
132*c2c66affSColin Finck mmap m(array + 0, array + 6);
133*c2c66affSColin Finck mmap::iterator i;
134*c2c66affSColin Finck i = m.lower_bound(3);
135*c2c66affSColin Finck CPPUNIT_ASSERT((*i).first==3);
136*c2c66affSColin Finck CPPUNIT_ASSERT((*i).second=='c');
137*c2c66affSColin Finck
138*c2c66affSColin Finck i = m.upper_bound(3);
139*c2c66affSColin Finck CPPUNIT_ASSERT((*i).first==6);
140*c2c66affSColin Finck CPPUNIT_ASSERT((*i).second=='f');
141*c2c66affSColin Finck }
142*c2c66affSColin Finck
143*c2c66affSColin Finck
iterators()144*c2c66affSColin Finck void MapTest::iterators()
145*c2c66affSColin Finck {
146*c2c66affSColin Finck typedef map<int, char, less<int> > int_map;
147*c2c66affSColin Finck int_map imap;
148*c2c66affSColin Finck {
149*c2c66affSColin Finck int_map::iterator ite(imap.begin());
150*c2c66affSColin Finck int_map::const_iterator cite(imap.begin());
151*c2c66affSColin Finck CPPUNIT_ASSERT( ite == cite );
152*c2c66affSColin Finck CPPUNIT_ASSERT( !(ite != cite) );
153*c2c66affSColin Finck CPPUNIT_ASSERT( cite == ite );
154*c2c66affSColin Finck CPPUNIT_ASSERT( !(cite != ite) );
155*c2c66affSColin Finck }
156*c2c66affSColin Finck
157*c2c66affSColin Finck typedef multimap<int, char, less<int> > mmap;
158*c2c66affSColin Finck typedef mmap::value_type pair_type;
159*c2c66affSColin Finck
160*c2c66affSColin Finck pair_type p1(3, 'c');
161*c2c66affSColin Finck pair_type p2(6, 'f');
162*c2c66affSColin Finck pair_type p3(1, 'a');
163*c2c66affSColin Finck pair_type p4(2, 'b');
164*c2c66affSColin Finck pair_type p5(3, 'x');
165*c2c66affSColin Finck pair_type p6(6, 'f');
166*c2c66affSColin Finck
167*c2c66affSColin Finck pair_type array [] = {
168*c2c66affSColin Finck p1,
169*c2c66affSColin Finck p2,
170*c2c66affSColin Finck p3,
171*c2c66affSColin Finck p4,
172*c2c66affSColin Finck p5,
173*c2c66affSColin Finck p6
174*c2c66affSColin Finck };
175*c2c66affSColin Finck
176*c2c66affSColin Finck mmap m(array+0, array + 6);
177*c2c66affSColin Finck
178*c2c66affSColin Finck {
179*c2c66affSColin Finck mmap::iterator ite(m.begin());
180*c2c66affSColin Finck mmap::const_iterator cite(m.begin());
181*c2c66affSColin Finck //test compare between const_iterator and iterator
182*c2c66affSColin Finck CPPUNIT_ASSERT( ite == cite );
183*c2c66affSColin Finck CPPUNIT_ASSERT( !(ite != cite) );
184*c2c66affSColin Finck CPPUNIT_ASSERT( cite == ite );
185*c2c66affSColin Finck CPPUNIT_ASSERT( !(cite != ite) );
186*c2c66affSColin Finck }
187*c2c66affSColin Finck
188*c2c66affSColin Finck #if 0
189*c2c66affSColin Finck /*
190*c2c66affSColin Finck * A check that map and multimap iterators are NOT comparable
191*c2c66affSColin Finck * the following code should generate a compile time error
192*c2c66affSColin Finck */
193*c2c66affSColin Finck {
194*c2c66affSColin Finck int_map::iterator mite(imap.begin());
195*c2c66affSColin Finck int_map::const_iterator mcite(imap.begin());
196*c2c66affSColin Finck mmap::iterator mmite(m.begin());
197*c2c66affSColin Finck mmap::const_iterator mmcite(m.begin());
198*c2c66affSColin Finck CPPUNIT_ASSERT( !(mite == mmite) );
199*c2c66affSColin Finck CPPUNIT_ASSERT( !(mcite == mmcite) );
200*c2c66affSColin Finck CPPUNIT_ASSERT( mite != mmite );
201*c2c66affSColin Finck CPPUNIT_ASSERT( mcite != mmcite );
202*c2c66affSColin Finck CPPUNIT_ASSERT( !(mite == mmcite) );
203*c2c66affSColin Finck CPPUNIT_ASSERT( !(mite == mmcite) );
204*c2c66affSColin Finck CPPUNIT_ASSERT( mite != mmcite );
205*c2c66affSColin Finck CPPUNIT_ASSERT( mite != mmcite );
206*c2c66affSColin Finck }
207*c2c66affSColin Finck
208*c2c66affSColin Finck #endif
209*c2c66affSColin Finck
210*c2c66affSColin Finck mmap::reverse_iterator ri = m.rbegin();
211*c2c66affSColin Finck CPPUNIT_ASSERT( ri != m.rend() );
212*c2c66affSColin Finck CPPUNIT_ASSERT( ri == m.rbegin() );
213*c2c66affSColin Finck CPPUNIT_ASSERT( (*ri).first == 6 );
214*c2c66affSColin Finck CPPUNIT_ASSERT( (*ri++).second == 'f' );
215*c2c66affSColin Finck CPPUNIT_ASSERT( (*ri).first == 6 );
216*c2c66affSColin Finck CPPUNIT_ASSERT( (*ri).second == 'f' );
217*c2c66affSColin Finck
218*c2c66affSColin Finck mmap const& cm = m;
219*c2c66affSColin Finck mmap::const_reverse_iterator rci = cm.rbegin();
220*c2c66affSColin Finck CPPUNIT_ASSERT( rci != cm.rend() );
221*c2c66affSColin Finck CPPUNIT_ASSERT( (*rci).first == 6 );
222*c2c66affSColin Finck CPPUNIT_ASSERT( (*rci++).second == 'f' );
223*c2c66affSColin Finck CPPUNIT_ASSERT( (*rci).first == 6 );
224*c2c66affSColin Finck CPPUNIT_ASSERT( (*rci).second == 'f' );
225*c2c66affSColin Finck }
226*c2c66affSColin Finck
equal_range()227*c2c66affSColin Finck void MapTest::equal_range()
228*c2c66affSColin Finck {
229*c2c66affSColin Finck typedef map<char, int, less<char> > maptype;
230*c2c66affSColin Finck {
231*c2c66affSColin Finck maptype m;
232*c2c66affSColin Finck m['x'] = 10;
233*c2c66affSColin Finck
234*c2c66affSColin Finck pair<maptype::iterator, maptype::iterator> ret;
235*c2c66affSColin Finck ret = m.equal_range('x');
236*c2c66affSColin Finck CPPUNIT_ASSERT( ret.first != ret.second );
237*c2c66affSColin Finck CPPUNIT_ASSERT( (*(ret.first)).first == 'x' );
238*c2c66affSColin Finck CPPUNIT_ASSERT( (*(ret.first)).second == 10 );
239*c2c66affSColin Finck CPPUNIT_ASSERT( ++(ret.first) == ret.second );
240*c2c66affSColin Finck }
241*c2c66affSColin Finck {
242*c2c66affSColin Finck {
243*c2c66affSColin Finck maptype m;
244*c2c66affSColin Finck
245*c2c66affSColin Finck maptype::iterator i = m.lower_bound( 'x' );
246*c2c66affSColin Finck CPPUNIT_ASSERT( i == m.end() );
247*c2c66affSColin Finck
248*c2c66affSColin Finck i = m.upper_bound( 'x' );
249*c2c66affSColin Finck CPPUNIT_ASSERT( i == m.end() );
250*c2c66affSColin Finck
251*c2c66affSColin Finck pair<maptype::iterator, maptype::iterator> ret;
252*c2c66affSColin Finck ret = m.equal_range('x');
253*c2c66affSColin Finck CPPUNIT_ASSERT( ret.first == ret.second );
254*c2c66affSColin Finck CPPUNIT_ASSERT( ret.first == m.end() );
255*c2c66affSColin Finck }
256*c2c66affSColin Finck
257*c2c66affSColin Finck {
258*c2c66affSColin Finck const maptype m;
259*c2c66affSColin Finck pair<maptype::const_iterator, maptype::const_iterator> ret;
260*c2c66affSColin Finck ret = m.equal_range('x');
261*c2c66affSColin Finck CPPUNIT_ASSERT( ret.first == ret.second );
262*c2c66affSColin Finck CPPUNIT_ASSERT( ret.first == m.end() );
263*c2c66affSColin Finck }
264*c2c66affSColin Finck }
265*c2c66affSColin Finck }
266*c2c66affSColin Finck
allocator_with_state()267*c2c66affSColin Finck void MapTest::allocator_with_state()
268*c2c66affSColin Finck {
269*c2c66affSColin Finck char buf1[1024];
270*c2c66affSColin Finck StackAllocator<pair<const int, int> > stack1(buf1, buf1 + sizeof(buf1));
271*c2c66affSColin Finck
272*c2c66affSColin Finck char buf2[1024];
273*c2c66affSColin Finck StackAllocator<pair<const int, int> > stack2(buf2, buf2 + sizeof(buf2));
274*c2c66affSColin Finck
275*c2c66affSColin Finck {
276*c2c66affSColin Finck typedef map<int, int, less<int>, StackAllocator<pair<const int, int> > > MapInt;
277*c2c66affSColin Finck less<int> intLess;
278*c2c66affSColin Finck MapInt mint1(intLess, stack1);
279*c2c66affSColin Finck int i;
280*c2c66affSColin Finck for (i = 0; i < 5; ++i)
281*c2c66affSColin Finck mint1.insert(MapInt::value_type(i, i));
282*c2c66affSColin Finck MapInt mint1Cpy(mint1);
283*c2c66affSColin Finck
284*c2c66affSColin Finck MapInt mint2(intLess, stack2);
285*c2c66affSColin Finck for (; i < 10; ++i)
286*c2c66affSColin Finck mint2.insert(MapInt::value_type(i, i));
287*c2c66affSColin Finck MapInt mint2Cpy(mint2);
288*c2c66affSColin Finck
289*c2c66affSColin Finck mint1.swap(mint2);
290*c2c66affSColin Finck
291*c2c66affSColin Finck CPPUNIT_ASSERT( mint1.get_allocator().swaped() );
292*c2c66affSColin Finck CPPUNIT_ASSERT( mint2.get_allocator().swaped() );
293*c2c66affSColin Finck
294*c2c66affSColin Finck CPPUNIT_ASSERT( mint1 == mint2Cpy );
295*c2c66affSColin Finck CPPUNIT_ASSERT( mint2 == mint1Cpy );
296*c2c66affSColin Finck CPPUNIT_ASSERT( mint1.get_allocator() == stack2 );
297*c2c66affSColin Finck CPPUNIT_ASSERT( mint2.get_allocator() == stack1 );
298*c2c66affSColin Finck }
299*c2c66affSColin Finck CPPUNIT_ASSERT( stack1.ok() );
300*c2c66affSColin Finck CPPUNIT_ASSERT( stack2.ok() );
301*c2c66affSColin Finck }
302*c2c66affSColin Finck
303*c2c66affSColin Finck struct Key
304*c2c66affSColin Finck {
KeyKey305*c2c66affSColin Finck Key() : m_data(0) {}
KeyKey306*c2c66affSColin Finck explicit Key(int data) : m_data(data) {}
307*c2c66affSColin Finck
308*c2c66affSColin Finck int m_data;
309*c2c66affSColin Finck };
310*c2c66affSColin Finck
311*c2c66affSColin Finck struct KeyCmp
312*c2c66affSColin Finck {
operator ()KeyCmp313*c2c66affSColin Finck bool operator () (Key lhs, Key rhs) const
314*c2c66affSColin Finck { return lhs.m_data < rhs.m_data; }
315*c2c66affSColin Finck
operator ()KeyCmp316*c2c66affSColin Finck bool operator () (Key lhs, int rhs) const
317*c2c66affSColin Finck { return lhs.m_data < rhs; }
318*c2c66affSColin Finck
operator ()KeyCmp319*c2c66affSColin Finck bool operator () (int lhs, Key rhs) const
320*c2c66affSColin Finck { return lhs < rhs.m_data; }
321*c2c66affSColin Finck };
322*c2c66affSColin Finck
323*c2c66affSColin Finck struct KeyCmpPtr
324*c2c66affSColin Finck {
operator ()KeyCmpPtr325*c2c66affSColin Finck bool operator () (Key const volatile *lhs, Key const volatile *rhs) const
326*c2c66affSColin Finck { return (*lhs).m_data < (*rhs).m_data; }
327*c2c66affSColin Finck
operator ()KeyCmpPtr328*c2c66affSColin Finck bool operator () (Key const volatile *lhs, int rhs) const
329*c2c66affSColin Finck { return (*lhs).m_data < rhs; }
330*c2c66affSColin Finck
operator ()KeyCmpPtr331*c2c66affSColin Finck bool operator () (int lhs, Key const volatile *rhs) const
332*c2c66affSColin Finck { return lhs < (*rhs).m_data; }
333*c2c66affSColin Finck };
334*c2c66affSColin Finck
template_methods()335*c2c66affSColin Finck void MapTest::template_methods()
336*c2c66affSColin Finck {
337*c2c66affSColin Finck #if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
338*c2c66affSColin Finck {
339*c2c66affSColin Finck typedef map<Key, int, KeyCmp> Container;
340*c2c66affSColin Finck typedef Container::value_type value;
341*c2c66affSColin Finck Container cont;
342*c2c66affSColin Finck cont.insert(value(Key(1), 1));
343*c2c66affSColin Finck cont.insert(value(Key(2), 2));
344*c2c66affSColin Finck cont.insert(value(Key(3), 3));
345*c2c66affSColin Finck cont.insert(value(Key(4), 4));
346*c2c66affSColin Finck
347*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
348*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(1) == 1 );
349*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(5) == 0 );
350*c2c66affSColin Finck
351*c2c66affSColin Finck CPPUNIT_ASSERT( cont.find(2) != cont.end() );
352*c2c66affSColin Finck CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
353*c2c66affSColin Finck CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
354*c2c66affSColin Finck CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
355*c2c66affSColin Finck
356*c2c66affSColin Finck Container const& ccont = cont;
357*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
358*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
359*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
360*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
361*c2c66affSColin Finck }
362*c2c66affSColin Finck
363*c2c66affSColin Finck {
364*c2c66affSColin Finck typedef map<Key*, int, KeyCmpPtr> Container;
365*c2c66affSColin Finck typedef Container::value_type value;
366*c2c66affSColin Finck Container cont;
367*c2c66affSColin Finck Key key1(1), key2(2), key3(3), key4(4);
368*c2c66affSColin Finck cont.insert(value(&key1, 1));
369*c2c66affSColin Finck cont.insert(value(&key2, 2));
370*c2c66affSColin Finck cont.insert(value(&key3, 3));
371*c2c66affSColin Finck cont.insert(value(&key4, 4));
372*c2c66affSColin Finck
373*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(1) == 1 );
374*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(5) == 0 );
375*c2c66affSColin Finck
376*c2c66affSColin Finck CPPUNIT_ASSERT( cont.find(2) != cont.end() );
377*c2c66affSColin Finck CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
378*c2c66affSColin Finck CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
379*c2c66affSColin Finck CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
380*c2c66affSColin Finck
381*c2c66affSColin Finck Container const& ccont = cont;
382*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
383*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
384*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
385*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
386*c2c66affSColin Finck }
387*c2c66affSColin Finck {
388*c2c66affSColin Finck typedef multimap<Key, int, KeyCmp> Container;
389*c2c66affSColin Finck typedef Container::value_type value;
390*c2c66affSColin Finck Container cont;
391*c2c66affSColin Finck cont.insert(value(Key(1), 1));
392*c2c66affSColin Finck cont.insert(value(Key(2), 2));
393*c2c66affSColin Finck cont.insert(value(Key(3), 3));
394*c2c66affSColin Finck cont.insert(value(Key(4), 4));
395*c2c66affSColin Finck
396*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
397*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(1) == 1 );
398*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(5) == 0 );
399*c2c66affSColin Finck
400*c2c66affSColin Finck CPPUNIT_ASSERT( cont.find(2) != cont.end() );
401*c2c66affSColin Finck CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
402*c2c66affSColin Finck CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
403*c2c66affSColin Finck CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
404*c2c66affSColin Finck
405*c2c66affSColin Finck Container const& ccont = cont;
406*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
407*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
408*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
409*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
410*c2c66affSColin Finck }
411*c2c66affSColin Finck
412*c2c66affSColin Finck {
413*c2c66affSColin Finck typedef multimap<Key const volatile*, int, KeyCmpPtr> Container;
414*c2c66affSColin Finck typedef Container::value_type value;
415*c2c66affSColin Finck Container cont;
416*c2c66affSColin Finck Key key1(1), key2(2), key3(3), key4(4);
417*c2c66affSColin Finck cont.insert(value(&key1, 1));
418*c2c66affSColin Finck cont.insert(value(&key2, 2));
419*c2c66affSColin Finck cont.insert(value(&key3, 3));
420*c2c66affSColin Finck cont.insert(value(&key4, 4));
421*c2c66affSColin Finck
422*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(1) == 1 );
423*c2c66affSColin Finck CPPUNIT_ASSERT( cont.count(5) == 0 );
424*c2c66affSColin Finck
425*c2c66affSColin Finck CPPUNIT_ASSERT( cont.find(2) != cont.end() );
426*c2c66affSColin Finck CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
427*c2c66affSColin Finck CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
428*c2c66affSColin Finck CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
429*c2c66affSColin Finck
430*c2c66affSColin Finck Container const& ccont = cont;
431*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
432*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
433*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
434*c2c66affSColin Finck CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
435*c2c66affSColin Finck }
436*c2c66affSColin Finck #endif
437*c2c66affSColin Finck }
438*c2c66affSColin Finck
439*c2c66affSColin Finck #if !defined (STLPORT) || \
440*c2c66affSColin Finck !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
441*c2c66affSColin Finck # if !defined (__DMC__)
442*c2c66affSColin Finck /* Simple compilation test: Check that nested types like iterator
443*c2c66affSColin Finck * can be access even if type used to instanciate container is not
444*c2c66affSColin Finck * yet completely defined.
445*c2c66affSColin Finck */
446*c2c66affSColin Finck class IncompleteClass
447*c2c66affSColin Finck {
448*c2c66affSColin Finck map<IncompleteClass, IncompleteClass> instances;
449*c2c66affSColin Finck typedef map<IncompleteClass, IncompleteClass>::iterator it;
450*c2c66affSColin Finck multimap<IncompleteClass, IncompleteClass> minstances;
451*c2c66affSColin Finck typedef multimap<IncompleteClass, IncompleteClass>::iterator mit;
452*c2c66affSColin Finck };
453*c2c66affSColin Finck # endif
454*c2c66affSColin Finck #endif
455