Fixed iterator issues in set/map
[libcds.git] / tests / test-hdr / ordered_list / hdr_michael_kv.h
1 //$$CDS-header$$
2
3 #include "cppunit/cppunit_proxy.h"
4 #include <cds/container/details/michael_list_base.h>
5
6 namespace ordlist {
7     namespace cc = cds::container;
8     namespace co = cds::container::opt;
9
10     class MichaelKVListTestHeader: public CppUnitMini::TestCase
11     {
12     public:
13         typedef int key_type;
14         struct value_type {
15             int m_val;
16
17             value_type()
18                 : m_val(0)
19             {}
20
21             value_type( int n )
22                 : m_val( n )
23             {}
24         };
25
26         template <typename T>
27         struct lt
28         {
29             bool operator ()(const T& v1, const T& v2 ) const
30             {
31                 return v1 < v2;
32             }
33         };
34
35         template <typename T>
36         struct cmp {
37             int operator ()(const T& v1, const T& v2 ) const
38             {
39                 if ( v1 < v2 )
40                     return -1;
41                 return v1 > v2 ? 1 : 0;
42             }
43         };
44
45         struct check_value {
46             int     m_nExpected;
47
48             check_value( int nExpected )
49                 : m_nExpected( nExpected )
50             {}
51
52             template <typename T>
53             void operator ()( T& pair )
54             {
55                 CPPUNIT_ASSERT_CURRENT( pair.second.m_val == m_nExpected );
56             }
57         };
58
59         struct insert_functor {
60             template <typename T>
61             void operator()( T& pair )
62             {
63                 pair.second.m_val = pair.first * 10;
64             }
65         };
66
67         struct ensure_functor {
68             template <typename T>
69             void operator()( bool bNew, T& pair )
70             {
71                 pair.second.m_val = pair.first * 50;
72             }
73         };
74
75         struct erase_functor {
76             int     nKey;
77             int     nVal;
78
79             erase_functor()
80                 : nKey(0)
81                 , nVal(0)
82             {}
83
84             template <typename T>
85             void operator()( T& i )
86             {
87                 nKey = i.first;
88                 nVal = i.second.m_val;
89             }
90         };
91
92         typedef float other_key;
93         struct other_less {
94             bool operator()( float f, int i ) const
95             {
96                 return int(f) < i;
97             }
98             bool operator()( int i, float f ) const
99             {
100                 return i < int(f);
101             }
102         };
103
104     protected:
105         template <class OrdList>
106         void test_with( OrdList& l)
107         {
108             typedef typename OrdList::value_type    value_type;
109
110             typename OrdList::iterator itTest;
111             typename OrdList::const_iterator citTest;
112
113             CPPUNIT_ASSERT( l.empty() );
114
115             // insert / find test
116             CPPUNIT_ASSERT( !l.find( 100 ));
117             CPPUNIT_ASSERT( l.insert( 100 ));
118             CPPUNIT_ASSERT( !l.empty() );
119             CPPUNIT_ASSERT( l.find( 100 ));
120
121             check_value chk(0);
122             CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
123
124             CPPUNIT_ASSERT( !l.find_with( 50, lt<key_type>() ));
125             CPPUNIT_ASSERT( l.insert( 50, 500 ));
126             CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ));
127             CPPUNIT_ASSERT( !l.insert( 50, 5 ));
128             chk.m_nExpected = 500;
129             CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>(), std::ref( chk ) ) );
130             chk.m_nExpected = 0;
131             CPPUNIT_ASSERT( l.find_with( 100, lt<key_type>(), std::ref( chk ) ) );
132             CPPUNIT_ASSERT( !l.empty() );
133
134             CPPUNIT_ASSERT( !l.find( 150 ));
135             CPPUNIT_ASSERT( l.insert_key( 150, insert_functor() ));
136             CPPUNIT_ASSERT( l.find( 150 ));
137             chk.m_nExpected = 1500;
138             CPPUNIT_ASSERT( l.find( 150, std::ref( chk ) ) );
139             chk.m_nExpected = 0;
140             CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
141             chk.m_nExpected = 500;
142             CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
143             CPPUNIT_ASSERT( !l.empty() );
144
145             // erase test
146
147             CPPUNIT_ASSERT( !l.erase( 500 ));
148             CPPUNIT_ASSERT( !l.empty() );
149
150             CPPUNIT_ASSERT( l.find( 50 ));
151             {
152                 erase_functor ef;
153                 l.erase( 50, std::ref( ef ) );
154                 CPPUNIT_ASSERT( ef.nKey == 50 );
155                 CPPUNIT_ASSERT( ef.nVal == 500 );
156             }
157             CPPUNIT_ASSERT( !l.find( 50 ));
158
159             // ensure test
160             std::pair<bool, bool> bEnsureResult;
161             bEnsureResult = l.ensure( 100, ensure_functor() );
162             CPPUNIT_ASSERT( bEnsureResult.first );
163             CPPUNIT_ASSERT( !bEnsureResult.second );
164             chk.m_nExpected = 5000;
165             CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
166
167             {
168                 ensure_functor ef;
169                 bEnsureResult = l.ensure( 50, std::ref( ef ) );
170             }
171             CPPUNIT_ASSERT( bEnsureResult.first );
172             CPPUNIT_ASSERT( bEnsureResult.second );
173             chk.m_nExpected = 2500;
174             CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
175
176             // erase test
177             CPPUNIT_ASSERT( !l.empty() );
178             CPPUNIT_ASSERT( l.insert_key( 200, insert_functor() ));
179             CPPUNIT_ASSERT( l.insert( 25 ));
180             CPPUNIT_ASSERT( l.erase( 100 ));
181             CPPUNIT_ASSERT( l.erase( 150 ));
182             {
183                 erase_functor ef;
184                 CPPUNIT_ASSERT( l.erase_with( 200, lt<key_type>(), std::ref(ef)) );
185                 CPPUNIT_ASSERT( ef.nKey == 200 );
186                 CPPUNIT_ASSERT( ef.nVal == 2000 );
187             }
188             CPPUNIT_ASSERT( l.erase_with( 25, lt<key_type>()))
189             CPPUNIT_ASSERT( l.erase( 50 ));
190             CPPUNIT_ASSERT( l.empty() );
191
192             // clear empty list
193             l.clear();
194             CPPUNIT_ASSERT( l.empty() );
195
196             // insert test
197             CPPUNIT_ASSERT( l.emplace( 501 ) );
198             CPPUNIT_ASSERT( l.emplace( 251, 152 ));
199
200             // insert failed - such key exists
201             CPPUNIT_ASSERT( !l.emplace( 501, 2 ) );
202             CPPUNIT_ASSERT( !l.emplace( 251, 10) );
203
204             check_value cv(0);
205             CPPUNIT_ASSERT( l.find( 501, std::ref(cv) ));
206             cv.m_nExpected = 152;
207             CPPUNIT_ASSERT( l.find( 251, std::ref(cv) ));
208
209             l.clear();
210             CPPUNIT_ASSERT( l.empty() );
211
212             // Iterator test
213             {
214                 int nCount = 100;
215                 for ( int i = 0; i < nCount; ++i )
216                     CPPUNIT_ASSERT( l.insert(i, i * 2 ) );
217
218                 {
219                     typename OrdList::iterator it( l.begin() );
220                     typename OrdList::const_iterator cit( l.cbegin() );
221                     CPPUNIT_CHECK( it == cit );
222                     CPPUNIT_CHECK( it != l.end() );
223                     CPPUNIT_CHECK( it != l.cend() );
224                     CPPUNIT_CHECK( cit != l.end() );
225                     CPPUNIT_CHECK( cit != l.cend() );
226                     ++it;
227                     CPPUNIT_CHECK( it != cit );
228                     CPPUNIT_CHECK( it != l.end() );
229                     CPPUNIT_CHECK( it != l.cend() );
230                     CPPUNIT_CHECK( cit != l.end() );
231                     CPPUNIT_CHECK( cit != l.cend() );
232                     ++cit;
233                     CPPUNIT_CHECK( it == cit );
234                     CPPUNIT_CHECK( it != l.end() );
235                     CPPUNIT_CHECK( it != l.cend() );
236                     CPPUNIT_CHECK( cit != l.end() );
237                     CPPUNIT_CHECK( cit != l.cend() );
238                 }
239
240                 int i = 0;
241                 for ( typename OrdList::iterator it = l.begin(), itEnd = l.end(); it != itEnd; ++it, ++i ) {
242                     CPPUNIT_ASSERT( it.key() == i );
243                     CPPUNIT_ASSERT( it->first == i );
244                     CPPUNIT_ASSERT( (*it).first == i );
245
246                     CPPUNIT_ASSERT( it.val().m_val == i * 2 );
247                     CPPUNIT_ASSERT( it->second.m_val == i * 2 );
248                     CPPUNIT_ASSERT( (*it).second.m_val == i * 2 );
249                     it.val().m_val = i * 3;
250                 }
251
252                 // Check that we have visited all items
253                 for ( int i = 0; i < nCount; ++i ) {
254                     chk.m_nExpected = i * 3;
255                     CPPUNIT_ASSERT( l.find( i, std::ref( chk ) ) );
256                 }
257
258                 l.clear();
259                 CPPUNIT_ASSERT( l.empty() );
260
261                 // Const iterator
262                 for ( int i = 0; i < nCount; ++i )
263                     CPPUNIT_ASSERT( l.insert(i, i * 7) );
264
265                 i = 0;
266                 const OrdList& rl = l;
267                 for ( typename OrdList::const_iterator it = rl.begin(), itEnd = rl.end(); it != itEnd; ++it, ++i ) {
268                     CPPUNIT_ASSERT( it.key() == i );
269                     CPPUNIT_ASSERT( it->first == i );
270                     CPPUNIT_ASSERT( (*it).first == i );
271
272                     CPPUNIT_ASSERT( it.val().m_val == i * 7 );
273                     CPPUNIT_ASSERT( it->second.m_val == i * 7 );
274                     CPPUNIT_ASSERT( (*it).second.m_val == i * 7 );
275                 }
276
277                 // Check that we have visited all items
278                 for ( int i = 0; i < nCount; ++i ) {
279                     chk.m_nExpected = i * 7;
280                     CPPUNIT_ASSERT( l.find_with( i, lt<key_type>(), std::ref( chk ) ) );
281                 }
282
283                 l.clear();
284                 CPPUNIT_ASSERT( l.empty() );
285             }
286         }
287
288         template <class OrdList>
289         void test()
290         {
291             OrdList l;
292             test_with(l);
293
294             typedef typename OrdList::guarded_ptr guarded_ptr;
295
296             static int const nLimit = 20;
297             int arr[nLimit];
298             for ( int i = 0; i < nLimit; i++ )
299                 arr[i] = i;
300             std::random_shuffle( arr, arr + nLimit );
301
302             // extract/get
303             for ( int i = 0; i < nLimit; ++i )
304                 l.insert( arr[i], arr[i] * 2 );
305             {
306                 guarded_ptr gp;
307                 for ( int i = 0; i < nLimit; ++i ) {
308                     int nKey = arr[i];
309
310                     CPPUNIT_ASSERT( l.get(gp, nKey));
311                     CPPUNIT_ASSERT( !gp.empty());
312                     CPPUNIT_CHECK( gp->first == nKey );
313                     CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
314                     gp.release();
315
316                     CPPUNIT_ASSERT( l.extract(gp, nKey));
317                     CPPUNIT_ASSERT( !gp.empty());
318                     CPPUNIT_CHECK( gp->first == nKey );
319                     CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
320                     gp.release();
321
322                     CPPUNIT_CHECK( !l.get(gp, nKey));
323                     CPPUNIT_CHECK( gp.empty());
324                     CPPUNIT_CHECK( !l.extract( gp, nKey));
325                     CPPUNIT_CHECK( gp.empty());
326                 }
327                 CPPUNIT_ASSERT( l.empty());
328                 CPPUNIT_CHECK( !l.get(gp, arr[0]));
329                 CPPUNIT_CHECK( gp.empty());
330                 CPPUNIT_CHECK( !l.extract( gp, arr[0]));
331                 CPPUNIT_CHECK( gp.empty());
332             }
333
334             // extract_with/get_with
335             for ( int i = 0; i < nLimit; ++i )
336                 l.insert( arr[i], arr[i] * 2 );
337             {
338                 guarded_ptr gp;
339                 for ( int i = 0; i < nLimit; ++i ) {
340                     int nKey = arr[i];
341                     other_key key = float(nKey + 0.3);
342
343                     CPPUNIT_ASSERT( l.get_with(gp, key, other_less()));
344                     CPPUNIT_ASSERT( !gp.empty());
345                     CPPUNIT_CHECK( gp->first == nKey );
346                     CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
347                     gp.release();
348
349                     CPPUNIT_ASSERT( l.extract_with(gp, key, other_less()));
350                     CPPUNIT_ASSERT( !gp.empty());
351                     CPPUNIT_CHECK( gp->first == nKey );
352                     CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
353                     gp.release();
354
355                     CPPUNIT_CHECK( !l.get_with(gp, key, other_less()));
356                     CPPUNIT_CHECK( gp.empty());
357                     CPPUNIT_CHECK( !l.extract_with( gp, key, other_less()));
358                     CPPUNIT_CHECK( gp.empty());
359                 }
360                 CPPUNIT_ASSERT( l.empty());
361                 CPPUNIT_CHECK( !l.get_with(gp, 3.4f, other_less()));
362                 CPPUNIT_CHECK( gp.empty());
363                 CPPUNIT_CHECK( !l.extract_with( gp, 3.4f, other_less()));
364                 CPPUNIT_CHECK( gp.empty());
365             }
366         }
367
368         template <class OrdList>
369         void test_rcu()
370         {
371             OrdList l;
372             test_with(l);
373
374             static int const nLimit = 20;
375
376             typedef typename OrdList::rcu_lock rcu_lock;
377             typedef typename OrdList::value_type value_type;
378             typedef typename OrdList::gc rcu_type;
379
380             {
381                 int a[nLimit];
382                 for (int i = 0; i < nLimit; ++i)
383                     a[i]=i;
384                 std::random_shuffle( a, a + nLimit );
385
386                 // extract/get
387                 for ( int i = 0; i < nLimit; ++i )
388                     CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
389
390                 typename OrdList::exempt_ptr ep;
391
392                 for ( int i = 0; i < nLimit; ++i ) {
393                     {
394                         rcu_lock lock;
395                         value_type * pGet = l.get( a[i] );
396                         CPPUNIT_ASSERT( pGet != nullptr );
397                         CPPUNIT_CHECK( pGet->first == a[i] );
398                         CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
399
400                         CPPUNIT_ASSERT( l.extract( ep, a[i] ));
401                         CPPUNIT_ASSERT( !ep.empty() );
402                         CPPUNIT_CHECK( ep->first == a[i] );
403                         CPPUNIT_CHECK( (*ep).second.m_val == a[i] * 2 );
404                     }
405                     ep.release();
406                     {
407                         rcu_lock lock;
408                         CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
409                         CPPUNIT_CHECK( !l.extract( ep, a[i] ));
410                         CPPUNIT_CHECK( ep.empty() );
411                     }
412                 }
413                 CPPUNIT_ASSERT( l.empty() );
414
415                 {
416                     rcu_lock lock;
417                     CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
418                     CPPUNIT_CHECK( !l.extract( ep, a[0] ) );
419                     CPPUNIT_CHECK( ep.empty() );
420                 }
421
422                 // extract_with/get_with
423                 for ( int i = 0; i < nLimit; ++i ) {
424                     CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
425                 }
426
427                 for ( int i = 0; i < nLimit; ++i ) {
428                     float itm = a[i] + 0.3f;
429                     {
430                         rcu_lock lock;
431                         value_type * pGet = l.get_with( itm, other_less() );
432                         CPPUNIT_ASSERT( pGet != nullptr );
433                         CPPUNIT_CHECK( pGet->first == a[i] );
434                         CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
435
436                         CPPUNIT_ASSERT( l.extract_with( ep, itm, other_less() ));
437                         CPPUNIT_ASSERT( !ep.empty() );
438                         CPPUNIT_CHECK( ep->first == a[i] );
439                         CPPUNIT_CHECK( ep->second.m_val == a[i] * 2 );
440                     }
441                     ep.release();
442                     {
443                         rcu_lock lock;
444                         CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr );
445                         CPPUNIT_CHECK( !l.extract_with( ep, itm, other_less() ));
446                         CPPUNIT_CHECK( ep.empty() );
447                     }
448                 }
449                 CPPUNIT_ASSERT( l.empty() );
450
451                 {
452                     rcu_lock lock;
453                     CPPUNIT_CHECK( l.get_with( 3.14f, other_less() ) == nullptr );
454                     CPPUNIT_CHECK( !l.extract_with( ep, 3.14f, other_less() ));
455                     CPPUNIT_CHECK( ep.empty() );
456                 }
457             }
458
459         }
460
461         template <class OrdList>
462         void nogc_test()
463         {
464             typedef typename OrdList::value_type    value_type;
465             typedef typename OrdList::iterator      iterator;
466
467             {
468                 OrdList l;
469                 iterator it;
470
471                 CPPUNIT_ASSERT( l.empty() );
472
473                 // insert / find test
474                 CPPUNIT_ASSERT( l.find( 100 ) == l.end() );
475                 CPPUNIT_ASSERT( l.insert( 100 ) != l.end() );
476                 CPPUNIT_ASSERT( !l.empty() );
477                 it = l.find_with( 100, lt<key_type>() );
478                 CPPUNIT_ASSERT( it != l.end() );
479                 CPPUNIT_ASSERT( it.key() == 100 );
480                 CPPUNIT_ASSERT( it.val().m_val == 0 );
481
482                 CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ) == l.end() );
483                 CPPUNIT_ASSERT( l.insert( 50, 500 ) != l.end());
484                 it = l.find( 50 );
485                 CPPUNIT_ASSERT( it != l.end() );
486                 CPPUNIT_ASSERT( it.key() == 50 );
487                 CPPUNIT_ASSERT( it.val().m_val == 500 );
488
489                 CPPUNIT_ASSERT( l.insert( 50, 5 ) == l.end() );
490                 it = l.find( 50 );
491                 CPPUNIT_ASSERT( it != l.end() );
492                 CPPUNIT_ASSERT( it.key() == 50 );
493                 CPPUNIT_ASSERT( it.val().m_val == 500 );
494                 CPPUNIT_ASSERT( !l.empty() );
495
496                 CPPUNIT_ASSERT( l.find( 150 ) == l.end() );
497                 CPPUNIT_ASSERT( l.insert_key( 150, insert_functor() ) != l.end() );
498                 it = l.find( 150 );
499                 CPPUNIT_ASSERT( it != l.end() );
500                 CPPUNIT_ASSERT( it.key() == 150 );
501                 CPPUNIT_ASSERT( it.val().m_val == 1500 );
502                 it = l.find( 100 );
503                 CPPUNIT_ASSERT( it != l.end() );
504                 CPPUNIT_ASSERT( it.key() == 100 );
505                 CPPUNIT_ASSERT( it.val().m_val == 0 );
506                 it = l.find( 50 );
507                 CPPUNIT_ASSERT( it != l.end() );
508                 CPPUNIT_ASSERT( it.key() == 50 );
509                 CPPUNIT_ASSERT( it.val().m_val == 500 );
510                 it.val().m_val = 25;
511                 it = l.find( 50 );
512                 CPPUNIT_ASSERT( it != l.end() );
513                 CPPUNIT_ASSERT( it.key() == 50 );
514                 CPPUNIT_ASSERT( it.val().m_val == 25 );
515                 CPPUNIT_ASSERT( !l.empty() );
516
517                 // ensure existing item
518                 std::pair<iterator, bool> ensureResult;
519                 ensureResult = l.ensure( 100 );
520                 CPPUNIT_ASSERT( !ensureResult.second );
521                 CPPUNIT_ASSERT( ensureResult.first.key() == 100 );
522                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0   );
523                 ensureResult.first.val().m_val = 5;
524                 it = l.find( 100 );
525                 CPPUNIT_ASSERT( it != l.end() );
526                 CPPUNIT_ASSERT( it.key() == 100 );
527                 CPPUNIT_ASSERT( it.val().m_val == 5 );
528
529                 CPPUNIT_ASSERT( !l.empty() );
530
531                 // ensure new item
532                 ensureResult = l.ensure( 1000 );
533                 CPPUNIT_ASSERT( ensureResult.second );
534                 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
535                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0   );
536                 ensureResult.first.val().m_val = 33;
537                 ensureResult = l.ensure( 1000 );
538                 CPPUNIT_ASSERT( !ensureResult.second );
539                 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
540                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 33   );
541
542                 // clear test
543                 l.clear();
544                 CPPUNIT_ASSERT( l.empty() );
545
546                 // insert test
547                 CPPUNIT_ASSERT( l.emplace( 501 ) != l.end());
548                 CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
549
550                 // insert failed - such key exists
551                 CPPUNIT_ASSERT( l.emplace( 501, 2 ) == l.end());
552                 CPPUNIT_ASSERT( l.emplace( 251, 10) == l.end());
553
554                 it = l.find( 501 );
555                 CPPUNIT_ASSERT( it != l.end());
556                 CPPUNIT_ASSERT( it.key() == 501 );
557                 CPPUNIT_ASSERT( it.val().m_val == 0 );
558
559                 it = l.find( 251 );
560                 CPPUNIT_ASSERT( it != l.end());
561                 CPPUNIT_ASSERT( it.key() == 251 );
562                 CPPUNIT_ASSERT( it.val().m_val == 152 );
563
564                 l.clear();
565                 CPPUNIT_ASSERT( l.empty() );
566
567                 // Iterator test
568                 {
569                     int nCount = 100;
570                     for ( int i = 0; i < nCount; ++i )
571                         CPPUNIT_ASSERT( l.insert(i, i * 2 ) != l.end() );
572
573                     {
574                         typename OrdList::iterator it( l.begin() );
575                         typename OrdList::const_iterator cit( l.cbegin() );
576                         CPPUNIT_CHECK( it == cit );
577                         CPPUNIT_CHECK( it != l.end() );
578                         CPPUNIT_CHECK( it != l.cend() );
579                         CPPUNIT_CHECK( cit != l.end() );
580                         CPPUNIT_CHECK( cit != l.cend() );
581                         ++it;
582                         CPPUNIT_CHECK( it != cit );
583                         CPPUNIT_CHECK( it != l.end() );
584                         CPPUNIT_CHECK( it != l.cend() );
585                         CPPUNIT_CHECK( cit != l.end() );
586                         CPPUNIT_CHECK( cit != l.cend() );
587                         ++cit;
588                         CPPUNIT_CHECK( it == cit );
589                         CPPUNIT_CHECK( it != l.end() );
590                         CPPUNIT_CHECK( it != l.cend() );
591                         CPPUNIT_CHECK( cit != l.end() );
592                         CPPUNIT_CHECK( cit != l.cend() );
593                     }
594
595                     int i = 0;
596                     for ( typename OrdList::iterator iter = l.begin(), itEnd = l.end(); iter != itEnd; ++iter, ++i ) {
597                         CPPUNIT_ASSERT( iter.key() == i );
598                         CPPUNIT_ASSERT( iter->first == i );
599                         CPPUNIT_ASSERT( (*iter).first == i );
600
601                         CPPUNIT_ASSERT( iter.val().m_val == i * 2 );
602                         CPPUNIT_ASSERT( iter->second.m_val == i * 2 );
603                         CPPUNIT_ASSERT( (*iter).second.m_val == i * 2 );
604
605                         iter.val().m_val = i * 3;
606                     }
607
608                     // Check that we have visited all items
609                     for ( int i = 0; i < nCount; ++i ) {
610                         it = l.find( i );
611                         CPPUNIT_ASSERT( it != l.end() );
612                         CPPUNIT_ASSERT( it.key() == i );
613                         CPPUNIT_ASSERT( it.val().m_val == i * 3 );
614                     }
615
616                     l.clear();
617                     CPPUNIT_ASSERT( l.empty() );
618
619                     // Const iterator
620                     for ( int i = 0; i < nCount; ++i )
621                         CPPUNIT_ASSERT( l.insert(i, i * 7) != l.end() );
622
623                     i = 0;
624                     const OrdList& rl = l;
625                     for ( typename OrdList::const_iterator iter = rl.begin(), itEnd = rl.end(); iter != itEnd; ++iter, ++i ) {
626                         CPPUNIT_ASSERT( iter.key() == i );
627                         CPPUNIT_ASSERT( iter->first == i );
628                         CPPUNIT_ASSERT( (*iter).first == i );
629
630                         CPPUNIT_ASSERT( iter.val().m_val == i * 7 );
631                         CPPUNIT_ASSERT( iter->second.m_val == i * 7 );
632                         CPPUNIT_ASSERT( (*iter).second.m_val == i * 7 );
633
634                         // it.val().m_val = i * 3    ; // error: const-iterator
635                     }
636
637                     l.clear();
638                     CPPUNIT_ASSERT( l.empty() );
639                 }
640
641             }
642         }
643
644         void HP_cmp();
645         void HP_less();
646         void HP_cmpmix();
647         void HP_ic();
648
649         void DHP_cmp();
650         void DHP_less();
651         void DHP_cmpmix();
652         void DHP_ic();
653
654         void RCU_GPI_cmp();
655         void RCU_GPI_less();
656         void RCU_GPI_cmpmix();
657         void RCU_GPI_ic();
658
659         void RCU_GPB_cmp();
660         void RCU_GPB_less();
661         void RCU_GPB_cmpmix();
662         void RCU_GPB_ic();
663
664         void RCU_GPT_cmp();
665         void RCU_GPT_less();
666         void RCU_GPT_cmpmix();
667         void RCU_GPT_ic();
668
669         void RCU_SHB_cmp();
670         void RCU_SHB_less();
671         void RCU_SHB_cmpmix();
672         void RCU_SHB_ic();
673
674         void RCU_SHT_cmp();
675         void RCU_SHT_less();
676         void RCU_SHT_cmpmix();
677         void RCU_SHT_ic();
678
679         void NOGC_cmp();
680         void NOGC_less();
681         void NOGC_cmpmix();
682         void NOGC_ic();
683
684         CPPUNIT_TEST_SUITE(MichaelKVListTestHeader)
685             CPPUNIT_TEST(HP_cmp)
686             CPPUNIT_TEST(HP_less)
687             CPPUNIT_TEST(HP_cmpmix)
688             CPPUNIT_TEST(HP_ic)
689
690             CPPUNIT_TEST(DHP_cmp)
691             CPPUNIT_TEST(DHP_less)
692             CPPUNIT_TEST(DHP_cmpmix)
693             CPPUNIT_TEST(DHP_ic)
694
695             CPPUNIT_TEST(RCU_GPI_cmp)
696             CPPUNIT_TEST(RCU_GPI_less)
697             CPPUNIT_TEST(RCU_GPI_cmpmix)
698             CPPUNIT_TEST(RCU_GPI_ic)
699
700             CPPUNIT_TEST(RCU_GPB_cmp)
701             CPPUNIT_TEST(RCU_GPB_less)
702             CPPUNIT_TEST(RCU_GPB_cmpmix)
703             CPPUNIT_TEST(RCU_GPB_ic)
704
705             CPPUNIT_TEST(RCU_GPT_cmp)
706             CPPUNIT_TEST(RCU_GPT_less)
707             CPPUNIT_TEST(RCU_GPT_cmpmix)
708             CPPUNIT_TEST(RCU_GPT_ic)
709
710             CPPUNIT_TEST(RCU_SHB_cmp)
711             CPPUNIT_TEST(RCU_SHB_less)
712             CPPUNIT_TEST(RCU_SHB_cmpmix)
713             CPPUNIT_TEST(RCU_SHB_ic)
714
715             CPPUNIT_TEST(RCU_SHT_cmp)
716             CPPUNIT_TEST(RCU_SHT_less)
717             CPPUNIT_TEST(RCU_SHT_cmpmix)
718             CPPUNIT_TEST(RCU_SHT_ic)
719
720             CPPUNIT_TEST(NOGC_cmp)
721             CPPUNIT_TEST(NOGC_less)
722             CPPUNIT_TEST(NOGC_cmpmix)
723             CPPUNIT_TEST(NOGC_ic)
724         CPPUNIT_TEST_SUITE_END()
725     };
726
727 }   // namespace ordlist