5c6bbdb042ca181842cbc640fab62c4b1765201f
[libcds.git] / tests / test-hdr / ordered_list / hdr_lazy_kv.h
1 //$$CDS-header$$
2
3 #include "cppunit/cppunit_proxy.h"
4 #include <cds/container/details/lazy_list_base.h>
5
6 namespace ordlist {
7     namespace cc = cds::container;
8     namespace co = cds::container::opt;
9
10     class LazyKVListTestHeader: 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( 50, std::ref( chk ) ) );
130             chk.m_nExpected = 0;
131             CPPUNIT_ASSERT( l.find( 100, 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_with( 150, lt<key_type>(), 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.val().m_val == i * 2 );
244                     it.val().m_val = i * 3;
245                 }
246
247                 // Check that we have visited all items
248                 for ( int i = 0; i < nCount; ++i ) {
249                     chk.m_nExpected = i * 3;
250                     CPPUNIT_ASSERT( l.find( i, std::ref( chk ) ) );
251                 }
252
253                 l.clear();
254                 CPPUNIT_ASSERT( l.empty() );
255
256                 // Const iterator
257                 for ( int i = 0; i < nCount; ++i )
258                     CPPUNIT_ASSERT( l.insert(i, i * 7) );
259
260                 i = 0;
261                 const OrdList& rl = l;
262                 for ( typename OrdList::const_iterator it = rl.begin(), itEnd = rl.end(); it != itEnd; ++it, ++i ) {
263                     CPPUNIT_ASSERT( it.key() == i );
264                     CPPUNIT_ASSERT( it.val().m_val == i * 7 );
265                 }
266
267                 // Check that we have visited all items
268                 for ( int i = nCount; i > 0; --i ) {
269                     chk.m_nExpected = (i - 1) * 7;
270                     CPPUNIT_ASSERT( l.find_with( i - 1, lt<key_type>(), std::ref( chk ) ) );
271                 }
272
273                 l.clear();
274                 CPPUNIT_ASSERT( l.empty() );
275             }
276         }
277
278         template <class OrdList>
279         void test()
280         {
281             OrdList l;
282             test_with(l);
283
284             typedef typename OrdList::guarded_ptr guarded_ptr;
285
286             static int const nLimit = 20;
287             int arr[nLimit];
288             for ( int i = 0; i < nLimit; i++ )
289                 arr[i] = i;
290             std::random_shuffle( arr, arr + nLimit );
291
292             // extract/get
293             for ( int i = 0; i < nLimit; ++i )
294                 l.insert( arr[i], arr[i] * 2 );
295             {
296                 guarded_ptr gp;
297                 for ( int i = 0; i < nLimit; ++i ) {
298                     int nKey = arr[i];
299
300                     CPPUNIT_ASSERT( l.get(gp, nKey));
301                     CPPUNIT_ASSERT( !gp.empty());
302                     CPPUNIT_CHECK( gp->first == nKey );
303                     CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
304                     gp.release();
305
306                     CPPUNIT_ASSERT( l.extract(gp, nKey));
307                     CPPUNIT_ASSERT( !gp.empty());
308                     CPPUNIT_CHECK( gp->first == nKey );
309                     CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
310                     gp.release();
311
312                     CPPUNIT_CHECK( !l.get(gp, nKey));
313                     CPPUNIT_CHECK( gp.empty());
314                     CPPUNIT_CHECK( !l.extract( gp, nKey));
315                     CPPUNIT_CHECK( gp.empty());
316                 }
317                 CPPUNIT_ASSERT( l.empty());
318                 CPPUNIT_CHECK( !l.get(gp, arr[0]));
319                 CPPUNIT_CHECK( gp.empty());
320                 CPPUNIT_CHECK( !l.extract( gp, arr[0]));
321                 CPPUNIT_CHECK( gp.empty());
322             }
323
324             // extract_with/get_with
325             for ( int i = 0; i < nLimit; ++i )
326                 l.insert( arr[i], arr[i] * 2 );
327             {
328                 guarded_ptr gp;
329                 for ( int i = 0; i < nLimit; ++i ) {
330                     int nKey = arr[i];
331                     other_key key = float(nKey + 0.3);
332
333                     CPPUNIT_ASSERT( l.get_with(gp, key, other_less()));
334                     CPPUNIT_ASSERT( !gp.empty());
335                     CPPUNIT_CHECK( gp->first == nKey );
336                     CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
337                     gp.release();
338
339                     CPPUNIT_ASSERT( l.extract_with(gp, key, other_less()));
340                     CPPUNIT_ASSERT( !gp.empty());
341                     CPPUNIT_CHECK( gp->first == nKey );
342                     CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
343                     gp.release();
344
345                     CPPUNIT_CHECK( !l.get_with(gp, key, other_less()));
346                     CPPUNIT_CHECK( gp.empty());
347                     CPPUNIT_CHECK( !l.extract_with( gp, key, other_less()));
348                     CPPUNIT_CHECK( gp.empty());
349                 }
350                 CPPUNIT_ASSERT( l.empty());
351                 CPPUNIT_CHECK( !l.get_with(gp, 3.4f, other_less()));
352                 CPPUNIT_CHECK( gp.empty());
353                 CPPUNIT_CHECK( !l.extract_with( gp, 3.4f, other_less()));
354                 CPPUNIT_CHECK( gp.empty());
355             }
356         }
357
358         template <class OrdList>
359         void test_rcu()
360         {
361             OrdList l;
362             test_with(l);
363
364             static int const nLimit = 20;
365
366             typedef typename OrdList::rcu_lock rcu_lock;
367             typedef typename OrdList::value_type value_type;
368             typedef typename OrdList::gc rcu_type;
369
370             {
371                 int a[nLimit];
372                 for (int i = 0; i < nLimit; ++i)
373                     a[i]=i;
374                 std::random_shuffle( a, a + nLimit );
375
376                 // extract/get
377                 for ( int i = 0; i < nLimit; ++i )
378                     CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
379
380                 typename OrdList::exempt_ptr ep;
381
382                 for ( int i = 0; i < nLimit; ++i ) {
383                     {
384                         rcu_lock lock;
385                         value_type * pGet = l.get( a[i] );
386                         CPPUNIT_ASSERT( pGet != nullptr );
387                         CPPUNIT_CHECK( pGet->first == a[i] );
388                         CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
389
390                         ep = l.extract( a[i] );
391                         CPPUNIT_ASSERT( ep );
392                         CPPUNIT_ASSERT( !ep.empty() );
393                         CPPUNIT_CHECK( ep->first == a[i] );
394                         CPPUNIT_CHECK( (*ep).second.m_val == a[i] * 2 );
395                     }
396                     ep.release();
397                     {
398                         rcu_lock lock;
399                         CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
400                         ep = l.extract( a[i] );
401                         CPPUNIT_CHECK( !ep );
402                         CPPUNIT_CHECK( ep.empty() );
403                     }
404                 }
405                 CPPUNIT_ASSERT( l.empty() );
406
407                 {
408                     rcu_lock lock;
409                     CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
410                     CPPUNIT_CHECK( !l.extract( a[0] ) );
411                     //CPPUNIT_CHECK( ep.empty() );
412                 }
413
414                 // extract_with/get_with
415                 for ( int i = 0; i < nLimit; ++i ) {
416                     CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
417                 }
418
419                 for ( int i = 0; i < nLimit; ++i ) {
420                     float itm = a[i] + 0.3f;
421                     {
422                         rcu_lock lock;
423                         value_type * pGet = l.get_with( itm, other_less() );
424                         CPPUNIT_ASSERT( pGet != nullptr );
425                         CPPUNIT_CHECK( pGet->first == a[i] );
426                         CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
427
428                         ep = l.extract_with( itm, other_less() );
429                         CPPUNIT_ASSERT( ep );
430                         CPPUNIT_ASSERT( !ep.empty() );
431                         CPPUNIT_CHECK( ep->first == a[i] );
432                         CPPUNIT_CHECK( ep->second.m_val == a[i] * 2 );
433                     }
434                     ep.release();
435                     {
436                         rcu_lock lock;
437                         CPPUNIT_CHECK( l.get_with( itm, other_less()) == nullptr );
438                         ep = l.extract_with( itm, other_less() );
439                         CPPUNIT_CHECK( !ep );
440                         CPPUNIT_CHECK( ep.empty() );
441                     }
442                 }
443                 CPPUNIT_ASSERT( l.empty() );
444
445                 {
446                     rcu_lock lock;
447                     CPPUNIT_CHECK( l.get_with( 3.14f, other_less() ) == nullptr );
448                     CPPUNIT_CHECK( !l.extract_with( 3.14f, other_less() ));
449                     CPPUNIT_CHECK( ep.empty() );
450                 }
451             }
452         }
453
454         template <class OrdList>
455         void nogc_test()
456         {
457             typedef typename OrdList::value_type    value_type;
458             typedef typename OrdList::iterator      iterator;
459
460             {
461                 OrdList l;
462                 iterator it;
463
464                 CPPUNIT_ASSERT( l.empty() );
465
466                 // insert / find test
467                 CPPUNIT_ASSERT( l.find( 100 ) == l.end() );
468                 CPPUNIT_ASSERT( l.insert( 100 ) != l.end() );
469                 CPPUNIT_ASSERT( !l.empty() );
470                 it = l.find( 100 );
471                 CPPUNIT_ASSERT( it != l.end() );
472                 CPPUNIT_ASSERT( it.key() == 100 );
473                 CPPUNIT_ASSERT( it.val().m_val == 0 );
474
475                 CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ) == l.end() );
476                 CPPUNIT_ASSERT( l.insert( 50, 500 ) != l.end());
477                 it = l.find( 50 );
478                 CPPUNIT_ASSERT( it != l.end() );
479                 CPPUNIT_ASSERT( it.key() == 50 );
480                 CPPUNIT_ASSERT( it.val().m_val == 500 );
481
482                 CPPUNIT_ASSERT( l.insert( 50, 5 ) == l.end() );
483                 it = l.find( 50 );
484                 CPPUNIT_ASSERT( it != l.end() );
485                 CPPUNIT_ASSERT( it.key() == 50 );
486                 CPPUNIT_ASSERT( it.val().m_val == 500 );
487                 CPPUNIT_ASSERT( !l.empty() );
488
489                 CPPUNIT_ASSERT( l.find( 150 ) == l.end() );
490                 CPPUNIT_ASSERT( l.insert_key( 150, insert_functor() ) != l.end() );
491                 it = l.find( 150 );
492                 CPPUNIT_ASSERT( it != l.end() );
493                 CPPUNIT_ASSERT( it.key() == 150 );
494                 CPPUNIT_ASSERT( it.val().m_val == 1500 );
495                 it = l.find( 100 );
496                 CPPUNIT_ASSERT( it != l.end() );
497                 CPPUNIT_ASSERT( it.key() == 100 );
498                 CPPUNIT_ASSERT( it.val().m_val == 0 );
499                 it = l.find( 50 );
500                 CPPUNIT_ASSERT( it != l.end() );
501                 CPPUNIT_ASSERT( it.key() == 50 );
502                 CPPUNIT_ASSERT( it.val().m_val == 500 );
503                 it.val().m_val = 25;
504                 it = l.find( 50 );
505                 CPPUNIT_ASSERT( it != l.end() );
506                 CPPUNIT_ASSERT( it.key() == 50 );
507                 CPPUNIT_ASSERT( it.val().m_val == 25 );
508                 CPPUNIT_ASSERT( !l.empty() );
509
510                 // ensure existing item
511                 std::pair<iterator, bool> ensureResult;
512                 ensureResult = l.ensure( 100 );
513                 CPPUNIT_ASSERT( !ensureResult.second );
514                 CPPUNIT_ASSERT( ensureResult.first.key() == 100 );
515                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0   );
516                 ensureResult.first.val().m_val = 5;
517                 it = l.find( 100 );
518                 CPPUNIT_ASSERT( it != l.end() );
519                 CPPUNIT_ASSERT( it.key() == 100 );
520                 CPPUNIT_ASSERT( it.val().m_val == 5 );
521
522                 CPPUNIT_ASSERT( !l.empty() );
523
524                 // ensure new item
525                 ensureResult = l.ensure( 1000 );
526                 CPPUNIT_ASSERT( ensureResult.second );
527                 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
528                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0   );
529                 ensureResult.first.val().m_val = 33;
530                 ensureResult = l.ensure( 1000 );
531                 CPPUNIT_ASSERT( !ensureResult.second );
532                 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
533                 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 33   );
534
535                 // clear test
536                 l.clear();
537                 CPPUNIT_ASSERT( l.empty() );
538
539                 // insert test
540                 CPPUNIT_ASSERT( l.emplace( 501 ) != l.end());
541                 CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
542
543                 // insert failed - such key exists
544                 CPPUNIT_ASSERT( l.emplace( 501, 2 ) == l.end());
545                 CPPUNIT_ASSERT( l.emplace( 251, 10) == l.end());
546
547                 it = l.find(501);
548                 CPPUNIT_ASSERT( it != l.end() );
549                 CPPUNIT_ASSERT( it.key() == 501 );
550                 CPPUNIT_ASSERT( it.val().m_val == 0 );
551
552                 it = l.find(251);
553                 CPPUNIT_ASSERT( it != l.end() );
554                 CPPUNIT_ASSERT( it.key() == 251 );
555                 CPPUNIT_ASSERT( it.val().m_val == 152 );
556
557                 l.clear();
558                 CPPUNIT_ASSERT( l.empty() );
559
560                 // Iterator test
561                 {
562                     int nCount = 100;
563                     for ( int i = 0; i < nCount; ++i )
564                         CPPUNIT_ASSERT( l.insert(i, i * 2 ) != l.end() );
565
566                     {
567                         typename OrdList::iterator it( l.begin() );
568                         typename OrdList::const_iterator cit( l.cbegin() );
569                         CPPUNIT_CHECK( it == cit );
570                         CPPUNIT_CHECK( it != l.end() );
571                         CPPUNIT_CHECK( it != l.cend() );
572                         CPPUNIT_CHECK( cit != l.end() );
573                         CPPUNIT_CHECK( cit != l.cend() );
574                         ++it;
575                         CPPUNIT_CHECK( it != cit );
576                         CPPUNIT_CHECK( it != l.end() );
577                         CPPUNIT_CHECK( it != l.cend() );
578                         CPPUNIT_CHECK( cit != l.end() );
579                         CPPUNIT_CHECK( cit != l.cend() );
580                         ++cit;
581                         CPPUNIT_CHECK( it == cit );
582                         CPPUNIT_CHECK( it != l.end() );
583                         CPPUNIT_CHECK( it != l.cend() );
584                         CPPUNIT_CHECK( cit != l.end() );
585                         CPPUNIT_CHECK( cit != l.cend() );
586                     }
587
588                     int i = 0;
589                     for ( typename OrdList::iterator iter = l.begin(), itEnd = l.end(); iter != itEnd; ++iter, ++i ) {
590                         CPPUNIT_ASSERT( iter.key() == i );
591                         CPPUNIT_ASSERT( iter->first == i );
592                         CPPUNIT_ASSERT( (*iter).first == i );
593
594                         CPPUNIT_ASSERT( iter.val().m_val == i * 2 );
595                         CPPUNIT_ASSERT( iter->second.m_val == i * 2 );
596                         CPPUNIT_ASSERT( (*iter).second.m_val == i * 2 );
597
598                         iter.val().m_val = i * 3;
599                     }
600
601                     // Check that we have visited all items
602                     for ( int i = 0; i < nCount; ++i ) {
603                         it = l.find( i );
604                         CPPUNIT_ASSERT( it != l.end() );
605                         CPPUNIT_ASSERT( it.key() == i );
606                         CPPUNIT_ASSERT( it.val().m_val == i * 3 );
607                     }
608
609                     l.clear();
610                     CPPUNIT_ASSERT( l.empty() );
611
612                     // Const iterator
613                     for ( int i = 0; i < nCount; ++i )
614                         CPPUNIT_ASSERT( l.insert(i, i * 7) != l.end() );
615
616                     i = 0;
617                     const OrdList& rl = l;
618                     for ( typename OrdList::const_iterator iter = rl.begin(), itEnd = rl.end(); iter != itEnd; ++iter, ++i ) {
619                         CPPUNIT_ASSERT( iter.key() == i );
620                         CPPUNIT_ASSERT( iter->first == i );
621                         CPPUNIT_ASSERT( (*iter).first == i );
622
623                         CPPUNIT_ASSERT( iter.val().m_val == i * 7 );
624                         CPPUNIT_ASSERT( iter->second.m_val == i * 7 );
625                         CPPUNIT_ASSERT( (*iter).second.m_val == i * 7 );
626                         // it.val().m_val = i * 3    ; // error: const-iterator
627                     }
628
629                     l.clear();
630                     CPPUNIT_ASSERT( l.empty() );
631                 }
632
633             }
634         }
635
636         void HP_cmp();
637         void HP_less();
638         void HP_cmpmix();
639         void HP_ic();
640
641         void DHP_cmp();
642         void DHP_less();
643         void DHP_cmpmix();
644         void DHP_ic();
645
646         void RCU_GPI_cmp();
647         void RCU_GPI_less();
648         void RCU_GPI_cmpmix();
649         void RCU_GPI_ic();
650
651         void RCU_GPB_cmp();
652         void RCU_GPB_less();
653         void RCU_GPB_cmpmix();
654         void RCU_GPB_ic();
655
656         void RCU_GPT_cmp();
657         void RCU_GPT_less();
658         void RCU_GPT_cmpmix();
659         void RCU_GPT_ic();
660
661         void RCU_SHB_cmp();
662         void RCU_SHB_less();
663         void RCU_SHB_cmpmix();
664         void RCU_SHB_ic();
665
666         void RCU_SHT_cmp();
667         void RCU_SHT_less();
668         void RCU_SHT_cmpmix();
669         void RCU_SHT_ic();
670
671         void NOGC_cmp();
672         void NOGC_less();
673         void NOGC_cmpmix();
674         void NOGC_ic();
675
676         CPPUNIT_TEST_SUITE(LazyKVListTestHeader)
677             CPPUNIT_TEST(HP_cmp)
678             CPPUNIT_TEST(HP_less)
679             CPPUNIT_TEST(HP_cmpmix)
680             CPPUNIT_TEST(HP_ic)
681
682             CPPUNIT_TEST(DHP_cmp)
683             CPPUNIT_TEST(DHP_less)
684             CPPUNIT_TEST(DHP_cmpmix)
685             CPPUNIT_TEST(DHP_ic)
686
687             CPPUNIT_TEST(RCU_GPI_cmp)
688             CPPUNIT_TEST(RCU_GPI_less)
689             CPPUNIT_TEST(RCU_GPI_cmpmix)
690             CPPUNIT_TEST(RCU_GPI_ic)
691
692             CPPUNIT_TEST(RCU_GPB_cmp)
693             CPPUNIT_TEST(RCU_GPB_less)
694             CPPUNIT_TEST(RCU_GPB_cmpmix)
695             CPPUNIT_TEST(RCU_GPB_ic)
696
697             CPPUNIT_TEST(RCU_GPT_cmp)
698             CPPUNIT_TEST(RCU_GPT_less)
699             CPPUNIT_TEST(RCU_GPT_cmpmix)
700             CPPUNIT_TEST(RCU_GPT_ic)
701
702             CPPUNIT_TEST(RCU_SHB_cmp)
703             CPPUNIT_TEST(RCU_SHB_less)
704             CPPUNIT_TEST(RCU_SHB_cmpmix)
705             CPPUNIT_TEST(RCU_SHB_ic)
706
707             CPPUNIT_TEST(RCU_SHT_cmp)
708             CPPUNIT_TEST(RCU_SHT_less)
709             CPPUNIT_TEST(RCU_SHT_cmpmix)
710             CPPUNIT_TEST(RCU_SHT_ic)
711
712             CPPUNIT_TEST(NOGC_cmp)
713             CPPUNIT_TEST(NOGC_less)
714             CPPUNIT_TEST(NOGC_cmpmix)
715             CPPUNIT_TEST(NOGC_ic)
716         CPPUNIT_TEST_SUITE_END()
717     };
718
719 }   // namespace ordlist