4d9a3b3461665c4a174bc68ab7f93bf7ead8977d
[libcds.git] / tests / test-hdr / ordered_list / hdr_intrusive_lazy.h
1 //$$CDS-header$$
2
3 #include "cppunit/cppunit_proxy.h"
4 #include <cds/intrusive/details/lazy_list_base.h>
5
6 namespace ordlist {
7     namespace ci = cds::intrusive;
8     namespace co = cds::opt;
9
10     class IntrusiveLazyListHeaderTest: public CppUnitMini::TestCase
11     {
12     public:
13
14         struct stat {
15             int nDisposeCount;
16             int nEnsureExistsCall;
17             int nEnsureNewCall;
18             int nFindCall;
19             int nEraseCall;
20
21             stat()
22                 : nDisposeCount(0)
23                 , nEnsureExistsCall(0)
24                 , nEnsureNewCall(0)
25                 , nFindCall(0)
26                 , nEraseCall(0)
27             {}
28
29             stat( const stat& s )
30             {
31                 *this = s;
32             }
33
34             stat& operator =(const stat& s)
35             {
36                 memcpy( this, &s, sizeof(s));
37                 return *this;
38             }
39         };
40
41         template <typename GC>
42         struct base_int_item: public ci::lazy_list::node< GC >
43         {
44             int nKey;
45             int nVal;
46
47             mutable stat    s;
48
49             base_int_item()
50             {}
51
52             base_int_item(int key, int val)
53                 : nKey( key )
54                 , nVal(val)
55                 , s()
56             {}
57
58             base_int_item(const base_int_item& v )
59                 : nKey( v.nKey )
60                 , nVal( v.nVal )
61                 , s()
62             {}
63
64             const int& key() const
65             {
66                 return nKey;
67             }
68         };
69
70         template <typename GC>
71         struct member_int_item
72         {
73             int nKey;
74             int nVal;
75
76             ci::lazy_list::node< GC > hMember;
77
78             mutable stat s;
79
80             member_int_item()
81             {}
82
83             member_int_item(int key, int val)
84                 : nKey( key )
85                 , nVal(val)
86                 , s()
87             {}
88
89             member_int_item(const member_int_item& v )
90                 : nKey( v.nKey )
91                 , nVal( v.nVal )
92                 , s()
93             {}
94
95             const int& key() const
96             {
97                 return nKey;
98             }
99         };
100
101         template <typename T>
102         struct less
103         {
104             bool operator ()(const T& v1, const T& v2 ) const
105             {
106                 return v1.key() < v2.key();
107             }
108
109             template <typename Q>
110             bool operator ()(const T& v1, const Q& v2 ) const
111             {
112                 return v1.key() < v2;
113             }
114
115             template <typename Q>
116             bool operator ()(const Q& v1, const T& v2 ) const
117             {
118                 return v1 < v2.key();
119             }
120         };
121
122         template <typename T>
123         struct cmp {
124             int operator ()(const T& v1, const T& v2 ) const
125             {
126                 if ( v1.key() < v2.key() )
127                     return -1;
128                 return v1.key() > v2.key() ? 1 : 0;
129             }
130
131             template <typename Q>
132             int operator ()(const T& v1, const Q& v2 ) const
133             {
134                 if ( v1.key() < v2 )
135                     return -1;
136                 return v1.key() > v2 ? 1 : 0;
137             }
138
139             template <typename Q>
140             int operator ()(const Q& v1, const T& v2 ) const
141             {
142                 if ( v1 < v2.key() )
143                     return -1;
144                 return v1 > v2.key() ? 1 : 0;
145             }
146         };
147
148         struct other_item {
149             int nKey;
150
151             other_item( int n )
152                 : nKey(n)
153             {}
154         };
155
156         struct other_less {
157             template <typename T, typename Q>
158             bool operator()( T const& i1, Q const& i2) const
159             {
160                 return i1.nKey < i2.nKey;
161             }
162         };
163
164         struct faked_disposer
165         {
166             template <typename T>
167             void operator ()( T * p )
168             {
169                 ++p->s.nDisposeCount;
170             }
171         };
172
173         struct ensure_functor
174         {
175             template <typename T>
176             void operator ()(bool bNew, T& item, T& val )
177             {
178                 if ( bNew )
179                     ++item.s.nEnsureNewCall;
180                 else
181                     ++item.s.nEnsureExistsCall;
182             }
183         };
184
185         struct find_functor
186         {
187             template <typename T, typename Q>
188             void operator ()( T& item, Q& val )
189             {
190                 ++item.s.nFindCall;
191             }
192         };
193
194         struct erase_functor
195         {
196             template <typename T>
197             void operator()( T const& item )
198             {
199                 item.s.nEraseCall++;
200             }
201         };
202
203         template <class OrdList>
204         void test_int_common()
205         {
206             typedef typename OrdList::value_type    value_type;
207
208             value_type v1( 10, 50 );
209             value_type v2( 5, 25  );
210             value_type v3( 20, 100 );
211             {
212                 OrdList l;
213                 CPPUNIT_ASSERT( l.empty() );
214
215                 CPPUNIT_ASSERT( l.insert( v1 ))     ;   // true
216                 CPPUNIT_ASSERT( l.find( v1.key() ));
217
218                 CPPUNIT_ASSERT( v1.s.nFindCall == 0 );
219                 CPPUNIT_ASSERT( l.find( v1.key(), find_functor() ));
220                 CPPUNIT_ASSERT( v1.s.nFindCall == 1 );
221
222                 CPPUNIT_ASSERT( !l.find_with( v2.key(), less<value_type>() ));
223                 CPPUNIT_ASSERT( !l.find( v3.key(), find_functor() ));
224                 CPPUNIT_ASSERT( !l.empty() );
225
226                 //CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is raised
227
228                 {
229                     value_type v( v1 );
230                     CPPUNIT_ASSERT( !l.insert( v )) ;   // false
231                 }
232
233                 std::pair<bool, bool> ret = l.ensure( v2, ensure_functor() );
234                 CPPUNIT_ASSERT( ret.first );
235                 CPPUNIT_ASSERT( ret.second );
236                 CPPUNIT_ASSERT( v2.s.nEnsureNewCall == 1 );
237                 CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == 0 );
238
239                 //CPPUNIT_ASSERT( !l.insert( v2 ))    ;   // assertion "is_empty"
240
241                 CPPUNIT_ASSERT( l.find( v1.key() )) ;   // true
242
243                 CPPUNIT_ASSERT( v1.s.nFindCall == 1 );
244                 CPPUNIT_ASSERT( l.find( v1.key(), find_functor() ));
245                 CPPUNIT_ASSERT( v1.s.nFindCall == 2 );
246
247                 CPPUNIT_ASSERT( l.find( v2.key() ));
248
249                 CPPUNIT_ASSERT( v2.s.nFindCall == 0 );
250                 CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>(), find_functor() ));
251                 CPPUNIT_ASSERT( v2.s.nFindCall == 1 );
252
253                 CPPUNIT_ASSERT( !l.find( v3.key() ));
254
255                 {
256                     CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == 0 );
257                     CPPUNIT_ASSERT( v2.s.nEnsureNewCall == 1 );
258
259                     value_type v( v2 );
260                     ret = l.ensure( v, ensure_functor() );
261
262                     CPPUNIT_ASSERT( ret.first );
263                     CPPUNIT_ASSERT( !ret.second );
264                     CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == 1 );
265                     CPPUNIT_ASSERT( v2.s.nEnsureNewCall == 1 );
266                     CPPUNIT_ASSERT( v.s.nEnsureExistsCall == 0 );
267                     CPPUNIT_ASSERT( v.s.nEnsureNewCall == 0 );
268                 }
269
270                 CPPUNIT_ASSERT( !l.empty() );
271
272                 CPPUNIT_ASSERT( l.insert( v3 ))     ;   // true
273                 CPPUNIT_ASSERT( l.find( v3.key() ));
274
275                 CPPUNIT_ASSERT( v3.s.nFindCall == 0 );
276                 CPPUNIT_ASSERT( l.find( v3.key(), find_functor() ));
277                 CPPUNIT_ASSERT( v3.s.nFindCall == 1 );
278
279                 CPPUNIT_ASSERT( l.unlink( v2 ) );
280                 CPPUNIT_ASSERT( l.find( v1.key() )) ;   // true
281                 CPPUNIT_ASSERT( !l.find( v2.key() )) ;   // true
282                 CPPUNIT_ASSERT( l.find( v3.key() )) ;   // true
283                 CPPUNIT_ASSERT( !l.empty() );
284                 CPPUNIT_ASSERT( !l.unlink( v2 ) );
285
286                 {
287                     // v1 key is in the list but v NODE is not in the list
288                     value_type v( v1 );
289                     CPPUNIT_ASSERT( !l.unlink( v ) );
290                 }
291
292                 CPPUNIT_ASSERT( l.unlink( v1 ) );
293                 CPPUNIT_ASSERT( !l.unlink( v1 ) );
294                 CPPUNIT_ASSERT( !l.find( v1.key() ));
295                 CPPUNIT_ASSERT( !l.find( v2.key() ));
296                 CPPUNIT_ASSERT( l.find( v3.key() ));
297                 CPPUNIT_ASSERT( !l.empty() );
298                 CPPUNIT_ASSERT( !l.unlink( v1 ) );
299                 CPPUNIT_ASSERT( !l.unlink( v2 ) );
300
301                 CPPUNIT_ASSERT( l.unlink( v3 ) );
302                 CPPUNIT_ASSERT( !l.find( v1.key() ));
303                 CPPUNIT_ASSERT( !l.find_with( v2.key(), less<value_type>() ));
304                 CPPUNIT_ASSERT( !l.find( v3.key() ));
305                 CPPUNIT_ASSERT( l.empty() );
306                 CPPUNIT_ASSERT( !l.unlink( v1 ) );
307                 CPPUNIT_ASSERT( !l.unlink( v2 ) );
308                 CPPUNIT_ASSERT( !l.unlink( v3 ) );
309
310                 // Apply retired pointer to clean links
311                 OrdList::gc::force_dispose();
312
313                 stat s( v3.s );
314                 ret = l.ensure( v3, ensure_functor() );
315                 CPPUNIT_ASSERT( ret.first );
316                 CPPUNIT_ASSERT( ret.second );
317                 CPPUNIT_ASSERT( v3.s.nEnsureNewCall == s.nEnsureNewCall + 1);
318                 CPPUNIT_ASSERT( v3.s.nEnsureExistsCall == s.nEnsureExistsCall );
319                 CPPUNIT_ASSERT( !l.empty() );
320
321                 s = v2.s;
322                 ret = l.ensure( v2, ensure_functor() );
323                 CPPUNIT_ASSERT( ret.first );
324                 CPPUNIT_ASSERT( ret.second );
325                 CPPUNIT_ASSERT( v2.s.nEnsureNewCall == s.nEnsureNewCall + 1);
326                 CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == s.nEnsureExistsCall );
327                 CPPUNIT_ASSERT( !l.empty() );
328
329                 s = v1.s;
330                 ret = l.ensure( v1, ensure_functor() );
331                 CPPUNIT_ASSERT( ret.first );
332                 CPPUNIT_ASSERT( ret.second );
333                 CPPUNIT_ASSERT( v1.s.nEnsureNewCall == s.nEnsureNewCall + 1);
334                 CPPUNIT_ASSERT( v1.s.nEnsureExistsCall == s.nEnsureExistsCall );
335                 CPPUNIT_ASSERT( !l.empty() );
336
337                 // Erase test
338                 CPPUNIT_ASSERT( l.erase( v1.key()) );
339                 //CPPUNIT_ASSERT( v1.s.nDisposeCount == 0 );
340                 CPPUNIT_ASSERT( !l.empty() );
341
342                 CPPUNIT_ASSERT( v2.s.nEraseCall == 0 );
343                 CPPUNIT_ASSERT( l.erase_with( v2.key(), less<value_type>(), erase_functor()) );
344                 CPPUNIT_ASSERT( v2.s.nEraseCall == 1 );
345                 CPPUNIT_ASSERT( !l.erase_with( v2.key(), less<value_type>()));
346                 CPPUNIT_ASSERT( v2.s.nEraseCall == 1 );
347                 //CPPUNIT_ASSERT( v2.s.nDisposeCount == 0 );
348                 CPPUNIT_ASSERT( !l.empty() );
349
350                 CPPUNIT_ASSERT( !l.erase( v2 ));
351                 CPPUNIT_ASSERT( !l.erase( v1 ));
352                 //CPPUNIT_ASSERT( v2.s.nDisposeCount == 0 );
353                 CPPUNIT_ASSERT( !l.empty() );
354
355                 CPPUNIT_ASSERT( v3.s.nEraseCall == 0 );
356                 CPPUNIT_ASSERT( l.erase( v3, erase_functor() ));
357                 CPPUNIT_ASSERT( v3.s.nEraseCall == 1 );
358                 //CPPUNIT_ASSERT( v3.s.nDisposeCount == 0 );
359                 CPPUNIT_ASSERT( l.empty() );
360
361                 // Apply retired pointer to clean links
362                 OrdList::gc::force_dispose();
363
364                 // Unlink test
365                 CPPUNIT_ASSERT( l.insert( v1 ));
366                 CPPUNIT_ASSERT( l.insert( v3 ));
367                 CPPUNIT_ASSERT( !l.empty() );
368                 CPPUNIT_ASSERT( !l.unlink( v2 ));
369                 CPPUNIT_ASSERT( l.unlink( v1 ));
370                 CPPUNIT_ASSERT( !l.unlink( v1 ));
371                 CPPUNIT_ASSERT( l.unlink( v3 ));
372                 CPPUNIT_ASSERT( !l.unlink( v3 ));
373                 CPPUNIT_ASSERT( l.empty() );
374
375                 // Apply retired pointer
376                 OrdList::gc::force_dispose();
377                 CPPUNIT_ASSERT( v1.s.nDisposeCount == 3 );
378                 CPPUNIT_ASSERT( v2.s.nDisposeCount == 2 );
379                 CPPUNIT_ASSERT( v3.s.nDisposeCount == 3 );
380
381                 // Destructor test (call disposer)
382                 CPPUNIT_ASSERT( l.insert( v1 ));
383                 CPPUNIT_ASSERT( l.insert( v3 ));
384                 CPPUNIT_ASSERT( l.insert( v2 ));
385
386                 // Iterator test
387                 {
388                     typename OrdList::iterator it = l.begin();
389                     typename OrdList::const_iterator cit = l.cbegin();
390                     CPPUNIT_ASSERT( it != l.end() );
391                     CPPUNIT_ASSERT( it != l.cend() );
392                     CPPUNIT_ASSERT( cit != l.end() );
393                     CPPUNIT_ASSERT( cit != l.cend() );
394                     CPPUNIT_ASSERT( cit == it );
395
396                     CPPUNIT_ASSERT( it->nKey == v2.nKey );
397                     CPPUNIT_ASSERT( it->nVal == v2.nVal );
398                     CPPUNIT_ASSERT( ++it != l.end() );
399                     CPPUNIT_ASSERT( it->nKey == v1.nKey );
400                     CPPUNIT_ASSERT( it->nVal == v1.nVal );
401                     CPPUNIT_ASSERT( ++it != l.end() );
402                     CPPUNIT_ASSERT( it->nKey == v3.nKey );
403                     CPPUNIT_ASSERT( it->nVal == v3.nVal );
404                     CPPUNIT_ASSERT( ++it == l.end() );
405                 }
406
407                 {
408                     OrdList const & lref = l;
409                     typename OrdList::const_iterator it = lref.begin();
410                     CPPUNIT_ASSERT( it != l.end() );
411                     CPPUNIT_ASSERT( it->nKey == v2.nKey );
412                     CPPUNIT_ASSERT( it->nVal == v2.nVal );
413                     CPPUNIT_ASSERT( ++it != lref.end() );
414                     CPPUNIT_ASSERT( it->nKey == v1.nKey );
415                     CPPUNIT_ASSERT( it->nVal == v1.nVal );
416                     CPPUNIT_ASSERT( ++it != l.end() );
417                     CPPUNIT_ASSERT( it->nKey == v3.nKey );
418                     CPPUNIT_ASSERT( it->nVal == v3.nVal );
419                     CPPUNIT_ASSERT( ++it == l.end() );
420                 }
421             }
422
423             // Apply retired pointer
424             OrdList::gc::force_dispose();
425
426             CPPUNIT_ASSERT( v1.s.nDisposeCount == 4 );
427             CPPUNIT_ASSERT( v2.s.nDisposeCount == 3 );
428             CPPUNIT_ASSERT( v3.s.nDisposeCount == 4 );
429         }
430
431         template <class OrdList>
432         void test_int()
433         {
434             test_int_common<OrdList>();
435
436             OrdList l;
437             typename OrdList::guarded_ptr gp;
438
439             static int const nLimit = 20;
440             typename OrdList::value_type arrItem[nLimit];
441
442
443             {
444                 int a[nLimit];
445                 for (int i = 0; i < nLimit; ++i)
446                     a[i]=i;
447                 std::random_shuffle( a, a + nLimit );
448
449                 for (int i = 0; i < nLimit; ++i) {
450                     arrItem[i].nKey = a[i];
451                     arrItem[i].nVal = a[i] * 2;
452                 }
453
454                 // extract/get
455                 for ( int i = 0; i < nLimit; ++i )
456                     CPPUNIT_ASSERT( l.insert( arrItem[i] ) );
457
458                 for ( int i=0; i < nLimit; ++i ) {
459                     CPPUNIT_ASSERT( l.get( gp, arrItem[i].nKey ));
460                     CPPUNIT_ASSERT( !gp.empty());
461                     CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
462                     CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
463                     gp.release();
464
465                     CPPUNIT_ASSERT( l.extract( gp, arrItem[i].nKey ));
466                     CPPUNIT_ASSERT( !gp.empty());
467                     CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
468                     CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
469                     gp.release();
470
471                     CPPUNIT_ASSERT( !l.get( gp, arrItem[i].nKey ));
472                     CPPUNIT_ASSERT( gp.empty());
473                     CPPUNIT_ASSERT( !l.extract( gp, arrItem[i].nKey ));
474                     CPPUNIT_ASSERT( gp.empty());
475                 }
476                 CPPUNIT_ASSERT( l.empty() );
477                 CPPUNIT_ASSERT( !l.get( gp, nLimit/2 ));
478                 CPPUNIT_ASSERT( gp.empty());
479                 CPPUNIT_ASSERT( !l.extract( gp, nLimit/2 ));
480                 CPPUNIT_ASSERT( gp.empty());
481
482                 // Apply retired pointer
483                 OrdList::gc::force_dispose();
484
485                 // extract_with/get_with
486                 for ( int i = 0; i < nLimit; ++i )
487                     CPPUNIT_ASSERT( l.insert( arrItem[i] ) );
488
489                 for ( int i=0; i < nLimit; ++i ) {
490                     other_item itm( arrItem[i].nKey );
491                     CPPUNIT_ASSERT( l.get_with( gp, itm, other_less() ));
492                     CPPUNIT_ASSERT( !gp.empty());
493                     CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
494                     CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
495                     gp.release();
496
497                     CPPUNIT_ASSERT( l.extract_with( gp, itm, other_less() ));
498                     CPPUNIT_ASSERT( !gp.empty());
499                     CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey );
500                     CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal );
501                     gp.release();
502
503                     CPPUNIT_ASSERT( !l.get_with( gp, itm, other_less() ));
504                     CPPUNIT_ASSERT( gp.empty());
505                     CPPUNIT_ASSERT( !l.extract_with( gp, itm, other_less() ));
506                     CPPUNIT_ASSERT( gp.empty());
507                 }
508                 CPPUNIT_ASSERT( l.empty() );
509                 CPPUNIT_ASSERT( !l.get_with( gp, other_item(nLimit/2), other_less() ));
510                 CPPUNIT_ASSERT( gp.empty());
511                 CPPUNIT_ASSERT( !l.extract_with( gp, other_item(nLimit/2), other_less() ));
512                 CPPUNIT_ASSERT( gp.empty());
513
514                 // Apply retired pointer
515                 OrdList::gc::force_dispose();
516
517                 for ( int i=0; i < nLimit; i++ ) {
518                     CPPUNIT_ASSERT( arrItem[i].s.nDisposeCount == 2 );
519                 }
520             }
521         }
522
523         template <class OrdList>
524         void test_rcu_int()
525         {
526             test_int_common<OrdList>();
527
528             OrdList l;
529             static int const nLimit = 20;
530             typename OrdList::value_type arrItem[nLimit];
531
532             typedef typename OrdList::rcu_lock rcu_lock;
533             typedef typename OrdList::value_type value_type;
534             typedef typename OrdList::gc rcu_type;
535
536             {
537                 int a[nLimit];
538                 for (int i = 0; i < nLimit; ++i)
539                     a[i]=i;
540                 std::random_shuffle( a, a + nLimit );
541
542                 for (int i = 0; i < nLimit; ++i) {
543                     arrItem[i].nKey = a[i];
544                     arrItem[i].nVal = a[i] * 2;
545                 }
546
547                 typename OrdList::exempt_ptr ep;
548
549                 // extract/get
550                 for ( int i = 0; i < nLimit; ++i )
551                     CPPUNIT_ASSERT( l.insert( arrItem[i] ) );
552
553                 for ( int i = 0; i < nLimit; ++i ) {
554                     {
555                         rcu_lock lock;
556                         value_type * pGet = l.get( a[i] );
557                         CPPUNIT_ASSERT( pGet != nullptr );
558                         CPPUNIT_CHECK( pGet->nKey == a[i] );
559                         CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
560
561                         ep = l.extract( a[i] );
562                         CPPUNIT_ASSERT( ep );
563                         CPPUNIT_ASSERT( !ep.empty() );
564                         CPPUNIT_CHECK( ep->nKey == a[i] );
565                         CPPUNIT_CHECK( (*ep).nVal == a[i] * 2 );
566                     }
567                     ep.release();
568                     {
569                         rcu_lock lock;
570                         CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
571                         CPPUNIT_CHECK( !l.extract( a[i] ) );
572                         CPPUNIT_CHECK( ep.empty() );
573                     }
574                 }
575                 CPPUNIT_ASSERT( l.empty() );
576
577                 {
578                     rcu_lock lock;
579                     CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
580                     ep = l.extract( a[0] );
581                     CPPUNIT_CHECK( !ep );
582                     CPPUNIT_CHECK( ep.empty() );
583                 }
584                 // Apply retired pointer
585                 OrdList::gc::force_dispose();
586
587                 // extract_with/get_with
588                 for ( int i = 0; i < nLimit; ++i ) {
589                     CPPUNIT_ASSERT( l.insert( arrItem[i] ) );
590                 }
591
592                 for ( int i = 0; i < nLimit; ++i ) {
593                     other_item itm( a[i] );
594                     {
595                         rcu_lock lock;
596                         value_type * pGet = l.get_with( itm, other_less() );
597                         CPPUNIT_ASSERT( pGet != nullptr );
598                         CPPUNIT_CHECK( pGet->nKey == a[i] );
599                         CPPUNIT_CHECK( pGet->nVal == a[i] * 2 );
600
601                         ep = l.extract_with( itm, other_less() );
602                         CPPUNIT_ASSERT( ep );
603                         CPPUNIT_ASSERT( !ep.empty() );
604                         CPPUNIT_CHECK( ep->nKey == a[i] );
605                         CPPUNIT_CHECK( ep->nVal == a[i] * 2 );
606                     }
607                     ep.release();
608                     {
609                         rcu_lock lock;
610                         CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr );
611                         ep = l.extract_with( itm, other_less() );
612                         CPPUNIT_CHECK( !ep );
613                         CPPUNIT_CHECK( ep.empty() );
614                     }
615                 }
616                 CPPUNIT_ASSERT( l.empty() );
617
618                 {
619                     rcu_lock lock;
620                     CPPUNIT_CHECK( l.get_with( other_item( 0 ), other_less() ) == nullptr );
621                     CPPUNIT_CHECK( !l.extract_with( other_item(0), other_less() ));
622                     CPPUNIT_CHECK( ep.empty() );
623                 }
624                 // Apply retired pointer
625                 OrdList::gc::force_dispose();
626             }
627         }
628
629         template <class OrdList>
630         void test_nogc_int()
631         {
632             typedef typename OrdList::value_type    value_type;
633             {
634                 value_type v1( 10, 50 );
635                 value_type v2( 5, 25  );
636                 value_type v3( 20, 100 );
637                 {
638                     OrdList l;
639                     CPPUNIT_ASSERT( l.empty() );
640
641                     CPPUNIT_ASSERT( l.insert( v1 ))     ;   // true
642                     CPPUNIT_ASSERT( l.find( v1.key() ) == &v1 );
643
644                     CPPUNIT_ASSERT( v1.s.nFindCall == 0 );
645                     CPPUNIT_ASSERT( l.find( v1.key(), find_functor() ));
646                     CPPUNIT_ASSERT( v1.s.nFindCall == 1 );
647
648                     CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>() ) == nullptr );
649                     CPPUNIT_ASSERT( l.find( v3.key() ) == nullptr );
650                     CPPUNIT_ASSERT( !l.empty() );
651
652                     //CPPUNIT_ASSERT( !l.insert( v1 ))    ;   // assertion "is_empty" is raised
653
654                     {
655                         value_type v( v1 );
656                         CPPUNIT_ASSERT( !l.insert( v )) ;   // false
657                     }
658
659                     std::pair<bool, bool> ret = l.ensure( v2, ensure_functor() );
660                     CPPUNIT_ASSERT( ret.first );
661                     CPPUNIT_ASSERT( ret.second );
662                     CPPUNIT_ASSERT( v2.s.nEnsureNewCall == 1 );
663                     CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == 0 );
664
665                     //CPPUNIT_ASSERT( !l.insert( v2 ))    ;   // assertion "is_empty"
666
667                     CPPUNIT_ASSERT( l.find( v1.key() ) == &v1 ) ;   // true
668
669                     CPPUNIT_ASSERT( v1.s.nFindCall == 1 );
670                     CPPUNIT_ASSERT( l.find( v1.key(), find_functor() ));
671                     CPPUNIT_ASSERT( v1.s.nFindCall == 2 );
672
673                     CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>() ) == &v2 );
674
675                     CPPUNIT_ASSERT( v2.s.nFindCall == 0 );
676                     CPPUNIT_ASSERT( l.find_with( v2.key(), less<value_type>(), find_functor() ));
677                     CPPUNIT_ASSERT( v2.s.nFindCall == 1 );
678
679                     CPPUNIT_ASSERT( !l.find( v3.key() ));
680
681                     {
682                         value_type v( v2 );
683                         ret = l.ensure( v, ensure_functor() );
684
685                         CPPUNIT_ASSERT( ret.first );
686                         CPPUNIT_ASSERT( !ret.second );
687                         CPPUNIT_ASSERT( v2.s.nEnsureExistsCall == 1 );
688                         CPPUNIT_ASSERT( v.s.nEnsureExistsCall == 0 && v.s.nEnsureNewCall == 0 );
689                     }
690
691                     CPPUNIT_ASSERT( !l.empty() );
692
693                     CPPUNIT_ASSERT( l.insert( v3 ))     ;   // true
694                     CPPUNIT_ASSERT( l.find( v3.key() ) == &v3 );
695
696                     CPPUNIT_ASSERT( v3.s.nFindCall == 0 );
697                     CPPUNIT_ASSERT( l.find( v3.key(), find_functor() ));
698                     CPPUNIT_ASSERT( v3.s.nFindCall == 1 );
699
700                     {
701                         typename OrdList::iterator it = l.begin();
702                         typename OrdList::const_iterator cit = l.cbegin();
703                         CPPUNIT_ASSERT( it != l.end() );
704                         CPPUNIT_ASSERT( it != l.cend() );
705                         CPPUNIT_ASSERT( cit != l.end() );
706                         CPPUNIT_ASSERT( cit != l.cend() );
707                         CPPUNIT_ASSERT( cit == it );
708
709                         CPPUNIT_ASSERT( it->nKey == v2.nKey );
710                         CPPUNIT_ASSERT( it->nVal == v2.nVal );
711                         CPPUNIT_ASSERT( ++it != l.end() );
712                         CPPUNIT_ASSERT( it->nKey == v1.nKey );
713                         CPPUNIT_ASSERT( it->nVal == v1.nVal );
714                         CPPUNIT_ASSERT( it++ != l.end() );
715                         CPPUNIT_ASSERT( it->nKey == v3.nKey );
716                         CPPUNIT_ASSERT( it->nVal == v3.nVal );
717                         CPPUNIT_ASSERT( it++ != l.end() );
718                         CPPUNIT_ASSERT( it == l.end() );
719                     }
720
721                     {
722                         OrdList const & lref = l;
723                         typename OrdList::const_iterator it = lref.begin();
724                         CPPUNIT_ASSERT( it != l.end() );
725                         CPPUNIT_ASSERT( it->nKey == v2.nKey );
726                         CPPUNIT_ASSERT( it->nVal == v2.nVal );
727                         CPPUNIT_ASSERT( ++it != lref.end() );
728                         CPPUNIT_ASSERT( it->nKey == v1.nKey );
729                         CPPUNIT_ASSERT( it->nVal == v1.nVal );
730                         CPPUNIT_ASSERT( it++ != l.end() );
731                         CPPUNIT_ASSERT( it->nKey == v3.nKey );
732                         CPPUNIT_ASSERT( it->nVal == v3.nVal );
733                         CPPUNIT_ASSERT( it++ != lref.end() );
734                         CPPUNIT_ASSERT( it == l.end() );
735                     }
736                 }
737
738                 // Disposer called on list destruction
739                 CPPUNIT_ASSERT( v1.s.nDisposeCount == 1 );
740                 CPPUNIT_ASSERT( v2.s.nDisposeCount == 1 );
741                 CPPUNIT_ASSERT( v3.s.nDisposeCount == 1 );
742             }
743         }
744
745         void HP_base_cmp();
746         void HP_base_less();
747         void HP_base_cmpmix();
748         void HP_base_ic();
749         void HP_member_cmp();
750         void HP_member_less();
751         void HP_member_cmpmix();
752         void HP_member_ic();
753
754         void DHP_base_cmp();
755         void DHP_base_less();
756         void DHP_base_cmpmix();
757         void DHP_base_ic();
758         void DHP_member_cmp();
759         void DHP_member_less();
760         void DHP_member_cmpmix();
761         void DHP_member_ic();
762
763         void RCU_GPI_base_cmp();
764         void RCU_GPI_base_less();
765         void RCU_GPI_base_cmpmix();
766         void RCU_GPI_base_ic();
767         void RCU_GPI_member_cmp();
768         void RCU_GPI_member_less();
769         void RCU_GPI_member_cmpmix();
770         void RCU_GPI_member_ic();
771
772         void RCU_GPB_base_cmp();
773         void RCU_GPB_base_less();
774         void RCU_GPB_base_cmpmix();
775         void RCU_GPB_base_ic();
776         void RCU_GPB_member_cmp();
777         void RCU_GPB_member_less();
778         void RCU_GPB_member_cmpmix();
779         void RCU_GPB_member_ic();
780
781         void RCU_GPT_base_cmp();
782         void RCU_GPT_base_less();
783         void RCU_GPT_base_cmpmix();
784         void RCU_GPT_base_ic();
785         void RCU_GPT_member_cmp();
786         void RCU_GPT_member_less();
787         void RCU_GPT_member_cmpmix();
788         void RCU_GPT_member_ic();
789
790         void RCU_SHB_base_cmp();
791         void RCU_SHB_base_less();
792         void RCU_SHB_base_cmpmix();
793         void RCU_SHB_base_ic();
794         void RCU_SHB_member_cmp();
795         void RCU_SHB_member_less();
796         void RCU_SHB_member_cmpmix();
797         void RCU_SHB_member_ic();
798
799         void RCU_SHT_base_cmp();
800         void RCU_SHT_base_less();
801         void RCU_SHT_base_cmpmix();
802         void RCU_SHT_base_ic();
803         void RCU_SHT_member_cmp();
804         void RCU_SHT_member_less();
805         void RCU_SHT_member_cmpmix();
806         void RCU_SHT_member_ic();
807
808         void nogc_base_cmp();
809         void nogc_base_less();
810         void nogc_base_cmpmix();
811         void nogc_base_ic();
812         void nogc_member_cmp();
813         void nogc_member_less();
814         void nogc_member_cmpmix();
815         void nogc_member_ic();
816
817
818         CPPUNIT_TEST_SUITE(IntrusiveLazyListHeaderTest)
819             CPPUNIT_TEST(HP_base_cmp)
820             CPPUNIT_TEST(HP_base_less)
821             CPPUNIT_TEST(HP_base_cmpmix)
822             CPPUNIT_TEST(HP_base_ic)
823             CPPUNIT_TEST(HP_member_cmp)
824             CPPUNIT_TEST(HP_member_less)
825             CPPUNIT_TEST(HP_member_cmpmix)
826             CPPUNIT_TEST(HP_member_ic)
827
828             CPPUNIT_TEST(DHP_base_cmp)
829             CPPUNIT_TEST(DHP_base_less)
830             CPPUNIT_TEST(DHP_base_cmpmix)
831             CPPUNIT_TEST(DHP_base_ic)
832             CPPUNIT_TEST(DHP_member_cmp)
833             CPPUNIT_TEST(DHP_member_less)
834             CPPUNIT_TEST(DHP_member_cmpmix)
835             CPPUNIT_TEST(DHP_member_ic)
836
837             CPPUNIT_TEST(RCU_GPI_base_cmp)
838             CPPUNIT_TEST(RCU_GPI_base_less)
839             CPPUNIT_TEST(RCU_GPI_base_cmpmix)
840             CPPUNIT_TEST(RCU_GPI_base_ic)
841             CPPUNIT_TEST(RCU_GPI_member_cmp)
842             CPPUNIT_TEST(RCU_GPI_member_less)
843             CPPUNIT_TEST(RCU_GPI_member_cmpmix)
844             CPPUNIT_TEST(RCU_GPI_member_ic)
845
846             CPPUNIT_TEST(RCU_GPB_base_cmp)
847             CPPUNIT_TEST(RCU_GPB_base_less)
848             CPPUNIT_TEST(RCU_GPB_base_cmpmix)
849             CPPUNIT_TEST(RCU_GPB_base_ic)
850             CPPUNIT_TEST(RCU_GPB_member_cmp)
851             CPPUNIT_TEST(RCU_GPB_member_less)
852             CPPUNIT_TEST(RCU_GPB_member_cmpmix)
853             CPPUNIT_TEST(RCU_GPB_member_ic)
854
855             CPPUNIT_TEST(RCU_GPT_base_cmp)
856             CPPUNIT_TEST(RCU_GPT_base_less)
857             CPPUNIT_TEST(RCU_GPT_base_cmpmix)
858             CPPUNIT_TEST(RCU_GPT_base_ic)
859             CPPUNIT_TEST(RCU_GPT_member_cmp)
860             CPPUNIT_TEST(RCU_GPT_member_less)
861             CPPUNIT_TEST(RCU_GPT_member_cmpmix)
862             CPPUNIT_TEST(RCU_GPT_member_ic)
863
864             CPPUNIT_TEST(RCU_SHB_base_cmp)
865             CPPUNIT_TEST(RCU_SHB_base_less)
866             CPPUNIT_TEST(RCU_SHB_base_cmpmix)
867             CPPUNIT_TEST(RCU_SHB_base_ic)
868             CPPUNIT_TEST(RCU_SHB_member_cmp)
869             CPPUNIT_TEST(RCU_SHB_member_less)
870             CPPUNIT_TEST(RCU_SHB_member_cmpmix)
871             CPPUNIT_TEST(RCU_SHB_member_ic)
872
873             CPPUNIT_TEST(RCU_SHT_base_cmp)
874             CPPUNIT_TEST(RCU_SHT_base_less)
875             CPPUNIT_TEST(RCU_SHT_base_cmpmix)
876             CPPUNIT_TEST(RCU_SHT_base_ic)
877             CPPUNIT_TEST(RCU_SHT_member_cmp)
878             CPPUNIT_TEST(RCU_SHT_member_less)
879             CPPUNIT_TEST(RCU_SHT_member_cmpmix)
880             CPPUNIT_TEST(RCU_SHT_member_ic)
881
882             CPPUNIT_TEST(nogc_base_cmp)
883             CPPUNIT_TEST(nogc_base_less)
884             CPPUNIT_TEST(nogc_base_cmpmix)
885             CPPUNIT_TEST(nogc_base_ic)
886             CPPUNIT_TEST(nogc_member_cmp)
887             CPPUNIT_TEST(nogc_member_less)
888             CPPUNIT_TEST(nogc_member_cmpmix)
889             CPPUNIT_TEST(nogc_member_ic)
890
891         CPPUNIT_TEST_SUITE_END()
892     };
893 }   // namespace ordlist