ReactOS 0.4.15-dev-7842-g558ab78
MapTest Class Reference
Inheritance diagram for MapTest:
Collaboration diagram for MapTest:

Protected Member Functions

void map1 ()
 
void mmap1 ()
 
void mmap2 ()
 
void iterators ()
 
void equal_range ()
 
void allocator_with_state ()
 
void template_methods ()
 

Private Member Functions

 CPPUNIT_TEST_SUITE (MapTest)
 
 CPPUNIT_TEST (map1)
 
 CPPUNIT_TEST (mmap1)
 
 CPPUNIT_TEST (mmap2)
 
 CPPUNIT_TEST (iterators)
 
 CPPUNIT_TEST (equal_range)
 
 CPPUNIT_TEST (allocator_with_state)
 
 CPPUNIT_TEST (template_methods)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Attributes

 CPPUNIT_IGNORE
 

Detailed Description

Definition at line 17 of file map_test.cpp.

Member Function Documentation

◆ allocator_with_state()

void MapTest::allocator_with_state ( )
protected

Definition at line 267 of file map_test.cpp.

268{
269 char buf1[1024];
270 StackAllocator<pair<const int, int> > stack1(buf1, buf1 + sizeof(buf1));
271
272 char buf2[1024];
273 StackAllocator<pair<const int, int> > stack2(buf2, buf2 + sizeof(buf2));
274
275 {
277 less<int> intLess;
278 MapInt mint1(intLess, stack1);
279 int i;
280 for (i = 0; i < 5; ++i)
281 mint1.insert(MapInt::value_type(i, i));
282 MapInt mint1Cpy(mint1);
283
284 MapInt mint2(intLess, stack2);
285 for (; i < 10; ++i)
286 mint2.insert(MapInt::value_type(i, i));
287 MapInt mint2Cpy(mint2);
288
289 mint1.swap(mint2);
290
291 CPPUNIT_ASSERT( mint1.get_allocator().swaped() );
292 CPPUNIT_ASSERT( mint2.get_allocator().swaped() );
293
294 CPPUNIT_ASSERT( mint1 == mint2Cpy );
295 CPPUNIT_ASSERT( mint2 == mint1Cpy );
296 CPPUNIT_ASSERT( mint1.get_allocator() == stack2 );
297 CPPUNIT_ASSERT( mint2.get_allocator() == stack1 );
298 }
299 CPPUNIT_ASSERT( stack1.ok() );
300 CPPUNIT_ASSERT( stack2.ok() );
301}
Definition: _map.h:48
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

◆ CPPUNIT_TEST() [1/7]

MapTest::CPPUNIT_TEST ( allocator_with_state  )
private

◆ CPPUNIT_TEST() [2/7]

MapTest::CPPUNIT_TEST ( equal_range  )
private

◆ CPPUNIT_TEST() [3/7]

MapTest::CPPUNIT_TEST ( iterators  )
private

◆ CPPUNIT_TEST() [4/7]

MapTest::CPPUNIT_TEST ( map1  )
private

◆ CPPUNIT_TEST() [5/7]

MapTest::CPPUNIT_TEST ( mmap1  )
private

◆ CPPUNIT_TEST() [6/7]

MapTest::CPPUNIT_TEST ( mmap2  )
private

◆ CPPUNIT_TEST() [7/7]

MapTest::CPPUNIT_TEST ( template_methods  )
private

◆ CPPUNIT_TEST_SUITE()

MapTest::CPPUNIT_TEST_SUITE ( MapTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

MapTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ equal_range()

void MapTest::equal_range ( )
protected

Definition at line 227 of file map_test.cpp.

228{
229 typedef map<char, int, less<char> > maptype;
230 {
231 maptype m;
232 m['x'] = 10;
233
235 ret = m.equal_range('x');
236 CPPUNIT_ASSERT( ret.first != ret.second );
237 CPPUNIT_ASSERT( (*(ret.first)).first == 'x' );
238 CPPUNIT_ASSERT( (*(ret.first)).second == 10 );
239 CPPUNIT_ASSERT( ++(ret.first) == ret.second );
240 }
241 {
242 {
243 maptype m;
244
245 maptype::iterator i = m.lower_bound( 'x' );
246 CPPUNIT_ASSERT( i == m.end() );
247
248 i = m.upper_bound( 'x' );
249 CPPUNIT_ASSERT( i == m.end() );
250
252 ret = m.equal_range('x');
253 CPPUNIT_ASSERT( ret.first == ret.second );
254 CPPUNIT_ASSERT( ret.first == m.end() );
255 }
256
257 {
258 const maptype m;
260 ret = m.equal_range('x');
261 CPPUNIT_ASSERT( ret.first == ret.second );
262 CPPUNIT_ASSERT( ret.first == m.end() );
263 }
264 }
265}
const GLfloat * m
Definition: glext.h:10848
Definition: _pair.h:47
int ret

◆ iterators()

void MapTest::iterators ( )
protected

Definition at line 144 of file map_test.cpp.

145{
146 typedef map<int, char, less<int> > int_map;
147 int_map imap;
148 {
149 int_map::iterator ite(imap.begin());
150 int_map::const_iterator cite(imap.begin());
151 CPPUNIT_ASSERT( ite == cite );
152 CPPUNIT_ASSERT( !(ite != cite) );
153 CPPUNIT_ASSERT( cite == ite );
154 CPPUNIT_ASSERT( !(cite != ite) );
155 }
156
157 typedef multimap<int, char, less<int> > mmap;
158 typedef mmap::value_type pair_type;
159
160 pair_type p1(3, 'c');
161 pair_type p2(6, 'f');
162 pair_type p3(1, 'a');
163 pair_type p4(2, 'b');
164 pair_type p5(3, 'x');
165 pair_type p6(6, 'f');
166
167 pair_type array [] = {
168 p1,
169 p2,
170 p3,
171 p4,
172 p5,
173 p6
174 };
175
176 mmap m(array+0, array + 6);
177
178 {
179 mmap::iterator ite(m.begin());
180 mmap::const_iterator cite(m.begin());
181 //test compare between const_iterator and iterator
182 CPPUNIT_ASSERT( ite == cite );
183 CPPUNIT_ASSERT( !(ite != cite) );
184 CPPUNIT_ASSERT( cite == ite );
185 CPPUNIT_ASSERT( !(cite != ite) );
186 }
187
188#if 0
189 /*
190 * A check that map and multimap iterators are NOT comparable
191 * the following code should generate a compile time error
192 */
193 {
194 int_map::iterator mite(imap.begin());
195 int_map::const_iterator mcite(imap.begin());
196 mmap::iterator mmite(m.begin());
197 mmap::const_iterator mmcite(m.begin());
198 CPPUNIT_ASSERT( !(mite == mmite) );
199 CPPUNIT_ASSERT( !(mcite == mmcite) );
200 CPPUNIT_ASSERT( mite != mmite );
201 CPPUNIT_ASSERT( mcite != mmcite );
202 CPPUNIT_ASSERT( !(mite == mmcite) );
203 CPPUNIT_ASSERT( !(mite == mmcite) );
204 CPPUNIT_ASSERT( mite != mmcite );
205 CPPUNIT_ASSERT( mite != mmcite );
206 }
207
208#endif
209
210 mmap::reverse_iterator ri = m.rbegin();
211 CPPUNIT_ASSERT( ri != m.rend() );
212 CPPUNIT_ASSERT( ri == m.rbegin() );
213 CPPUNIT_ASSERT( (*ri).first == 6 );
214 CPPUNIT_ASSERT( (*ri++).second == 'f' );
215 CPPUNIT_ASSERT( (*ri).first == 6 );
216 CPPUNIT_ASSERT( (*ri).second == 'f' );
217
218 mmap const& cm = m;
219 mmap::const_reverse_iterator rci = cm.rbegin();
220 CPPUNIT_ASSERT( rci != cm.rend() );
221 CPPUNIT_ASSERT( (*rci).first == 6 );
222 CPPUNIT_ASSERT( (*rci++).second == 'f' );
223 CPPUNIT_ASSERT( (*rci).first == 6 );
224 CPPUNIT_ASSERT( (*rci).second == 'f' );
225}
Definition: _map.h:241

◆ map1()

void MapTest::map1 ( )
protected

Definition at line 47 of file map_test.cpp.

48{
49 typedef map<char, int, less<char> > maptype;
50 maptype m;
51 // Store mappings between roman numerals and decimals.
52 m['l'] = 50;
53 m['x'] = 20; // Deliberate mistake.
54 m['v'] = 5;
55 m['i'] = 1;
56// cout << "m['x'] = " << m['x'] << endl;
57 CPPUNIT_ASSERT( m['x']== 20 );
58 m['x'] = 10; // Correct mistake.
59 CPPUNIT_ASSERT( m['x']== 10 );
60 CPPUNIT_ASSERT( m['z']== 0 );
61 //cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
62 CPPUNIT_ASSERT( m.count('z') == 1 );
63 //cout << "m.count('z') = " << m.count('z') << endl;
65 CPPUNIT_ASSERT( p.second );
66 CPPUNIT_ASSERT( p.first != m.end() );
67 CPPUNIT_ASSERT( (*p.first).first == 'c' );
68 CPPUNIT_ASSERT( (*p.first).second == 100 );
69
70 p = m.insert(pair<const char, int>('c', 100));
71 CPPUNIT_ASSERT( !p.second ); // already existing pair
72 CPPUNIT_ASSERT( p.first != m.end() );
73 CPPUNIT_ASSERT( (*p.first).first == 'c' );
74 CPPUNIT_ASSERT( (*p.first).second == 100 );
75}
GLfloat GLfloat p
Definition: glext.h:8902

◆ mmap1()

void MapTest::mmap1 ( )
protected

Definition at line 77 of file map_test.cpp.

78{
79 typedef multimap<char, int, less<char> > mmap;
80 mmap m;
81 CPPUNIT_ASSERT(m.count('X')==0);
82
83 m.insert(pair<const char, int>('X', 10)); // Standard way.
84 CPPUNIT_ASSERT(m.count('X')==1);
85
86 m.insert(pair<const char, int>('X', 20)); // jbuck: standard way
87 CPPUNIT_ASSERT(m.count('X')==2);
88
89 m.insert(pair<const char, int>('Y', 32)); // jbuck: standard way
90 mmap::iterator i = m.find('X'); // Find first match.
91#ifndef _STLP_CONST
92# define _STLP_CONST const
93#endif
95 CPPUNIT_ASSERT(*i == p);
96 CPPUNIT_ASSERT((*i).first == 'X');
97 CPPUNIT_ASSERT((*i).second == 10);
98 i++;
99 CPPUNIT_ASSERT((*i).first == 'X');
100 CPPUNIT_ASSERT((*i).second == 20);
101 i++;
102 CPPUNIT_ASSERT((*i).first == 'Y');
103 CPPUNIT_ASSERT((*i).second == 32);
104 i++;
105 CPPUNIT_ASSERT(i == m.end());
106
107 size_t count = m.erase('X');
109}
GLuint GLuint GLsizei count
Definition: gl.h:1545

◆ mmap2()

void MapTest::mmap2 ( )
protected

Definition at line 110 of file map_test.cpp.

111{
112 typedef pair<const int, char> pair_type;
113
114 pair_type p1(3, 'c');
115 pair_type p2(6, 'f');
116 pair_type p3(1, 'a');
117 pair_type p4(2, 'b');
118 pair_type p5(3, 'x');
119 pair_type p6(6, 'f');
120
121 typedef multimap<int, char, less<int> > mmap;
122
123 pair_type array [] = {
124 p1,
125 p2,
126 p3,
127 p4,
128 p5,
129 p6
130 };
131
132 mmap m(array + 0, array + 6);
133 mmap::iterator i;
134 i = m.lower_bound(3);
135 CPPUNIT_ASSERT((*i).first==3);
136 CPPUNIT_ASSERT((*i).second=='c');
137
138 i = m.upper_bound(3);
139 CPPUNIT_ASSERT((*i).first==6);
140 CPPUNIT_ASSERT((*i).second=='f');
141}

◆ template_methods()

void MapTest::template_methods ( )
protected

Definition at line 335 of file map_test.cpp.

336{
337#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
338 {
339 typedef map<Key, int, KeyCmp> Container;
340 typedef Container::value_type value;
341 Container cont;
342 cont.insert(value(Key(1), 1));
343 cont.insert(value(Key(2), 2));
344 cont.insert(value(Key(3), 3));
345 cont.insert(value(Key(4), 4));
346
347 CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
348 CPPUNIT_ASSERT( cont.count(1) == 1 );
349 CPPUNIT_ASSERT( cont.count(5) == 0 );
350
351 CPPUNIT_ASSERT( cont.find(2) != cont.end() );
352 CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
353 CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
354 CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
355
356 Container const& ccont = cont;
357 CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
358 CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
359 CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
360 CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
361 }
362
363 {
364 typedef map<Key*, int, KeyCmpPtr> Container;
365 typedef Container::value_type value;
366 Container cont;
367 Key key1(1), key2(2), key3(3), key4(4);
368 cont.insert(value(&key1, 1));
369 cont.insert(value(&key2, 2));
370 cont.insert(value(&key3, 3));
371 cont.insert(value(&key4, 4));
372
373 CPPUNIT_ASSERT( cont.count(1) == 1 );
374 CPPUNIT_ASSERT( cont.count(5) == 0 );
375
376 CPPUNIT_ASSERT( cont.find(2) != cont.end() );
377 CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
378 CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
379 CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
380
381 Container const& ccont = cont;
382 CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
383 CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
384 CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
385 CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
386 }
387 {
388 typedef multimap<Key, int, KeyCmp> Container;
389 typedef Container::value_type value;
390 Container cont;
391 cont.insert(value(Key(1), 1));
392 cont.insert(value(Key(2), 2));
393 cont.insert(value(Key(3), 3));
394 cont.insert(value(Key(4), 4));
395
396 CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
397 CPPUNIT_ASSERT( cont.count(1) == 1 );
398 CPPUNIT_ASSERT( cont.count(5) == 0 );
399
400 CPPUNIT_ASSERT( cont.find(2) != cont.end() );
401 CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
402 CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
403 CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
404
405 Container const& ccont = cont;
406 CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
407 CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
408 CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
409 CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
410 }
411
412 {
414 typedef Container::value_type value;
415 Container cont;
416 Key key1(1), key2(2), key3(3), key4(4);
417 cont.insert(value(&key1, 1));
418 cont.insert(value(&key2, 2));
419 cont.insert(value(&key3, 3));
420 cont.insert(value(&key4, 4));
421
422 CPPUNIT_ASSERT( cont.count(1) == 1 );
423 CPPUNIT_ASSERT( cont.count(5) == 0 );
424
425 CPPUNIT_ASSERT( cont.find(2) != cont.end() );
426 CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() );
427 CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() );
428 CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
429
430 Container const& ccont = cont;
431 CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
432 CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() );
433 CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() );
434 CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
435 }
436#endif
437}
pair< _T1, _T2 > _STLP_CALL make_pair(_T1 __x, _T2 __y)
Definition: _pair.h:124
GLuint64EXT GLuint GLuint GLenum GLenum GLuint GLuint GLenum GLuint GLuint key1
Definition: glext.h:10608
Definition: pdh_main.c:94

Member Data Documentation

◆ CPPUNIT_IGNORE

MapTest::CPPUNIT_IGNORE
private

Definition at line 27 of file map_test.cpp.


The documentation for this class was generated from the following file: