3 #ifndef CDSTEST_HDR_LAZY_KV_H
4 #define CDSTEST_HDR_LAZY_KV_H
6 #include "cppunit/cppunit_proxy.h"
7 #include <cds/container/details/lazy_list_base.h>
10 namespace cc = cds::container;
11 namespace co = cds::container::opt;
13 class LazyKVListTestHeader: public CppUnitMini::TestCase
32 bool operator ()(const T& v1, const T& v2 ) const
40 int operator ()(const T& v1, const T& v2 ) const
44 return v1 > v2 ? 1 : 0;
50 bool operator ()(const T& v1, const T& v2 ) const
59 check_value( int nExpected )
60 : m_nExpected( nExpected )
64 void operator ()( T& pair )
66 CPPUNIT_ASSERT_CURRENT( pair.second.m_val == m_nExpected );
70 struct insert_functor {
72 void operator()( T& pair )
74 pair.second.m_val = pair.first * 10;
78 struct ensure_functor {
80 void operator()( bool /*bNew*/, T& pair )
82 pair.second.m_val = pair.first * 50;
86 struct erase_functor {
96 void operator()( T& i )
99 nVal = i.second.m_val;
103 typedef float other_key;
105 bool operator()( float f, int i ) const
109 bool operator()( int i, float f ) const
116 template <class OrdList>
117 void test_with( OrdList& l)
119 typedef typename OrdList::value_type value_type;
121 typename OrdList::iterator itTest;
122 typename OrdList::const_iterator citTest;
124 CPPUNIT_ASSERT( l.empty() );
126 // insert / find test
127 CPPUNIT_ASSERT( !l.find( 100 ));
128 CPPUNIT_ASSERT( l.insert( 100 ));
129 CPPUNIT_ASSERT( !l.empty() );
130 CPPUNIT_ASSERT( l.find( 100 ));
133 CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
135 CPPUNIT_ASSERT( !l.find_with( 50, lt<key_type>() ));
136 CPPUNIT_ASSERT( l.insert( 50, 500 ));
137 CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ));
138 CPPUNIT_ASSERT( !l.insert( 50, 5 ));
139 chk.m_nExpected = 500;
140 CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
142 CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
143 CPPUNIT_ASSERT( !l.empty() );
145 CPPUNIT_ASSERT( !l.find( 150 ));
146 CPPUNIT_ASSERT( l.insert_with( 150, insert_functor() ));
147 CPPUNIT_ASSERT( l.find( 150 ));
148 chk.m_nExpected = 1500;
149 CPPUNIT_ASSERT( l.find_with( 150, lt<key_type>(), std::ref( chk ) ) );
151 CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
152 chk.m_nExpected = 500;
153 CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
154 CPPUNIT_ASSERT( !l.empty() );
158 CPPUNIT_ASSERT( !l.erase( 500 ));
159 CPPUNIT_ASSERT( !l.empty() );
161 CPPUNIT_ASSERT( l.find( 50 ));
164 l.erase( 50, std::ref( ef ) );
165 CPPUNIT_ASSERT( ef.nKey == 50 );
166 CPPUNIT_ASSERT( ef.nVal == 500 );
168 CPPUNIT_ASSERT( !l.find( 50 ));
171 std::pair<bool, bool> bEnsureResult;
172 bEnsureResult = l.ensure( 100, ensure_functor() );
173 CPPUNIT_ASSERT( bEnsureResult.first );
174 CPPUNIT_ASSERT( !bEnsureResult.second );
175 chk.m_nExpected = 5000;
176 CPPUNIT_ASSERT( l.find( 100, std::ref( chk ) ) );
180 bEnsureResult = l.ensure( 50, std::ref( ef ) );
182 CPPUNIT_ASSERT( bEnsureResult.first );
183 CPPUNIT_ASSERT( bEnsureResult.second );
184 chk.m_nExpected = 2500;
185 CPPUNIT_ASSERT( l.find( 50, std::ref( chk ) ) );
188 CPPUNIT_ASSERT( !l.empty() );
189 CPPUNIT_ASSERT( l.insert_with( 200, insert_functor() ));
190 CPPUNIT_ASSERT( l.insert( 25 ));
191 CPPUNIT_ASSERT( l.erase( 100 ));
192 CPPUNIT_ASSERT( l.erase( 150 ));
195 CPPUNIT_ASSERT( l.erase_with( 200, lt<key_type>(), std::ref(ef)) );
196 CPPUNIT_ASSERT( ef.nKey == 200 );
197 CPPUNIT_ASSERT( ef.nVal == 2000 );
199 CPPUNIT_ASSERT( l.erase_with( 25, lt<key_type>()))
200 CPPUNIT_ASSERT( l.erase( 50 ));
201 CPPUNIT_ASSERT( l.empty() );
205 CPPUNIT_ASSERT( l.empty() );
208 CPPUNIT_ASSERT( l.emplace( 501 ) );
209 CPPUNIT_ASSERT( l.emplace( 251, 152 ));
211 // insert failed - such key exists
212 CPPUNIT_ASSERT( !l.emplace( 501, 2 ) );
213 CPPUNIT_ASSERT( !l.emplace( 251, 10) );
216 CPPUNIT_ASSERT( l.find( 501, std::ref(cv) ));
217 cv.m_nExpected = 152;
218 CPPUNIT_ASSERT( l.find( 251, std::ref(cv) ));
221 CPPUNIT_ASSERT( l.empty() );
226 for ( int i = 0; i < nCount; ++i )
227 CPPUNIT_ASSERT( l.insert(i, i * 2 ) );
230 typename OrdList::iterator it( l.begin() );
231 typename OrdList::const_iterator cit( l.cbegin() );
232 CPPUNIT_CHECK( it == cit );
233 CPPUNIT_CHECK( it != l.end() );
234 CPPUNIT_CHECK( it != l.cend() );
235 CPPUNIT_CHECK( cit != l.end() );
236 CPPUNIT_CHECK( cit != l.cend() );
238 CPPUNIT_CHECK( it != cit );
239 CPPUNIT_CHECK( it != l.end() );
240 CPPUNIT_CHECK( it != l.cend() );
241 CPPUNIT_CHECK( cit != l.end() );
242 CPPUNIT_CHECK( cit != l.cend() );
244 CPPUNIT_CHECK( it == cit );
245 CPPUNIT_CHECK( it != l.end() );
246 CPPUNIT_CHECK( it != l.cend() );
247 CPPUNIT_CHECK( cit != l.end() );
248 CPPUNIT_CHECK( cit != l.cend() );
252 for ( typename OrdList::iterator it = l.begin(), itEnd = l.end(); it != itEnd; ++it, ++i ) {
253 CPPUNIT_ASSERT( it.key() == i );
254 CPPUNIT_ASSERT( it.val().m_val == i * 2 );
255 it.val().m_val = i * 3;
258 // Check that we have visited all items
259 for ( int i = 0; i < nCount; ++i ) {
260 chk.m_nExpected = i * 3;
261 CPPUNIT_ASSERT( l.find( i, std::ref( chk ) ) );
265 CPPUNIT_ASSERT( l.empty() );
268 for ( int i = 0; i < nCount; ++i )
269 CPPUNIT_ASSERT( l.insert(i, i * 7) );
272 const OrdList& rl = l;
273 for ( typename OrdList::const_iterator it = rl.begin(), itEnd = rl.end(); it != itEnd; ++it, ++i ) {
274 CPPUNIT_ASSERT( it.key() == i );
275 CPPUNIT_ASSERT( it.val().m_val == i * 7 );
278 // Check that we have visited all items
279 for ( int i = nCount; i > 0; --i ) {
280 chk.m_nExpected = (i - 1) * 7;
281 CPPUNIT_ASSERT( l.find_with( i - 1, lt<key_type>(), std::ref( chk ) ) );
285 CPPUNIT_ASSERT( l.empty() );
289 template <class OrdList>
295 typedef typename OrdList::guarded_ptr guarded_ptr;
297 static int const nLimit = 20;
299 for ( int i = 0; i < nLimit; i++ )
301 shuffle( arr, arr + nLimit );
304 for ( int i = 0; i < nLimit; ++i )
305 l.insert( arr[i], arr[i] * 2 );
308 for ( int i = 0; i < nLimit; ++i ) {
312 CPPUNIT_ASSERT( gp );
313 CPPUNIT_ASSERT( !gp.empty());
314 CPPUNIT_CHECK( gp->first == nKey );
315 CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
318 gp = l.extract( nKey );
319 CPPUNIT_ASSERT( gp );
320 CPPUNIT_ASSERT( !gp.empty());
321 CPPUNIT_CHECK( gp->first == nKey );
322 CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
326 CPPUNIT_CHECK( !gp );
327 CPPUNIT_CHECK( gp.empty());
328 CPPUNIT_CHECK( !l.extract( nKey));
329 CPPUNIT_CHECK( gp.empty());
331 CPPUNIT_ASSERT( l.empty());
332 CPPUNIT_CHECK( !l.get(arr[0]));
333 CPPUNIT_CHECK( gp.empty());
334 CPPUNIT_CHECK( !l.extract( arr[0]));
335 CPPUNIT_CHECK( gp.empty());
338 // extract_with/get_with
339 for ( int i = 0; i < nLimit; ++i )
340 l.insert( arr[i], arr[i] * 2 );
343 for ( int i = 0; i < nLimit; ++i ) {
345 other_key key = float(nKey + 0.3);
347 gp = l.get_with( key, other_less() );
348 CPPUNIT_ASSERT( gp );
349 CPPUNIT_ASSERT( !gp.empty());
350 CPPUNIT_CHECK( gp->first == nKey );
351 CPPUNIT_CHECK( gp->second.m_val == nKey * 2 );
354 gp = l.extract_with( key, other_less() );
355 CPPUNIT_ASSERT( gp );
356 CPPUNIT_ASSERT( !gp.empty());
357 CPPUNIT_CHECK( gp->first == nKey );
358 CPPUNIT_CHECK( gp->second.m_val == nKey*2 );
361 gp = l.get_with( key, other_less() );
362 CPPUNIT_CHECK( !gp );
363 CPPUNIT_CHECK( gp.empty());
364 CPPUNIT_CHECK( !l.extract_with( key, other_less()));
365 CPPUNIT_CHECK( gp.empty());
367 CPPUNIT_ASSERT( l.empty());
368 CPPUNIT_CHECK( !l.get_with(3.4f, other_less()));
369 CPPUNIT_CHECK( gp.empty());
370 CPPUNIT_CHECK( !l.extract_with( 3.4f, other_less()));
371 CPPUNIT_CHECK( gp.empty());
375 template <class OrdList>
381 static int const nLimit = 20;
383 typedef typename OrdList::rcu_lock rcu_lock;
384 typedef typename OrdList::value_type value_type;
385 typedef typename OrdList::gc rcu_type;
389 for (int i = 0; i < nLimit; ++i)
391 shuffle( a, a + nLimit );
394 for ( int i = 0; i < nLimit; ++i )
395 CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
397 typename OrdList::exempt_ptr ep;
399 for ( int i = 0; i < nLimit; ++i ) {
402 value_type * pGet = l.get( a[i] );
403 CPPUNIT_ASSERT( pGet != nullptr );
404 CPPUNIT_CHECK( pGet->first == a[i] );
405 CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
407 ep = l.extract( a[i] );
408 CPPUNIT_ASSERT( ep );
409 CPPUNIT_ASSERT( !ep.empty() );
410 CPPUNIT_CHECK( ep->first == a[i] );
411 CPPUNIT_CHECK( (*ep).second.m_val == a[i] * 2 );
416 CPPUNIT_CHECK( l.get( a[i] ) == nullptr );
417 ep = l.extract( a[i] );
418 CPPUNIT_CHECK( !ep );
419 CPPUNIT_CHECK( ep.empty() );
422 CPPUNIT_ASSERT( l.empty() );
426 CPPUNIT_CHECK( l.get( a[0] ) == nullptr );
427 CPPUNIT_CHECK( !l.extract( a[0] ) );
430 // extract_with/get_with
431 for ( int i = 0; i < nLimit; ++i ) {
432 CPPUNIT_ASSERT( l.insert( a[i], a[i]*2 ) );
435 for ( int i = 0; i < nLimit; ++i ) {
436 float itm = a[i] + 0.3f;
439 value_type * pGet = l.get_with( itm, other_less() );
440 CPPUNIT_ASSERT( pGet != nullptr );
441 CPPUNIT_CHECK( pGet->first == a[i] );
442 CPPUNIT_CHECK( pGet->second.m_val == a[i] * 2 );
444 ep = l.extract_with( itm, other_less() );
445 CPPUNIT_ASSERT( ep );
446 CPPUNIT_ASSERT( !ep.empty() );
447 CPPUNIT_CHECK( ep->first == a[i] );
448 CPPUNIT_CHECK( ep->second.m_val == a[i] * 2 );
453 CPPUNIT_CHECK( l.get_with( itm, other_less()) == nullptr );
454 ep = l.extract_with( itm, other_less() );
455 CPPUNIT_CHECK( !ep );
456 CPPUNIT_CHECK( ep.empty() );
459 CPPUNIT_ASSERT( l.empty() );
463 CPPUNIT_CHECK( l.get_with( 3.14f, other_less() ) == nullptr );
464 CPPUNIT_CHECK( !l.extract_with( 3.14f, other_less() ));
465 CPPUNIT_CHECK( ep.empty() );
470 template <class OrdList>
473 typedef typename OrdList::value_type value_type;
474 typedef typename OrdList::iterator iterator;
480 CPPUNIT_ASSERT( l.empty() );
482 // insert / find test
483 CPPUNIT_ASSERT( l.find( 100 ) == l.end() );
484 CPPUNIT_ASSERT( l.insert( 100 ) != l.end() );
485 CPPUNIT_ASSERT( !l.empty() );
487 CPPUNIT_ASSERT( it != l.end() );
488 CPPUNIT_ASSERT( it.key() == 100 );
489 CPPUNIT_ASSERT( it.val().m_val == 0 );
491 CPPUNIT_ASSERT( l.find_with( 50, lt<key_type>() ) == l.end() );
492 CPPUNIT_ASSERT( l.insert( 50, 500 ) != l.end());
494 CPPUNIT_ASSERT( it != l.end() );
495 CPPUNIT_ASSERT( it.key() == 50 );
496 CPPUNIT_ASSERT( it.val().m_val == 500 );
498 CPPUNIT_ASSERT( l.insert( 50, 5 ) == l.end() );
500 CPPUNIT_ASSERT( it != l.end() );
501 CPPUNIT_ASSERT( it.key() == 50 );
502 CPPUNIT_ASSERT( it.val().m_val == 500 );
503 CPPUNIT_ASSERT( !l.empty() );
505 CPPUNIT_ASSERT( l.find( 150 ) == l.end() );
506 CPPUNIT_ASSERT( l.insert_with( 150, insert_functor() ) != l.end() );
508 CPPUNIT_ASSERT( it != l.end() );
509 CPPUNIT_ASSERT( it.key() == 150 );
510 CPPUNIT_ASSERT( it.val().m_val == 1500 );
512 CPPUNIT_ASSERT( it != l.end() );
513 CPPUNIT_ASSERT( it.key() == 100 );
514 CPPUNIT_ASSERT( it.val().m_val == 0 );
516 CPPUNIT_ASSERT( it != l.end() );
517 CPPUNIT_ASSERT( it.key() == 50 );
518 CPPUNIT_ASSERT( it.val().m_val == 500 );
521 CPPUNIT_ASSERT( it != l.end() );
522 CPPUNIT_ASSERT( it.key() == 50 );
523 CPPUNIT_ASSERT( it.val().m_val == 25 );
524 CPPUNIT_ASSERT( !l.empty() );
526 // ensure existing item
527 std::pair<iterator, bool> ensureResult;
528 ensureResult = l.ensure( 100 );
529 CPPUNIT_ASSERT( !ensureResult.second );
530 CPPUNIT_ASSERT( ensureResult.first.key() == 100 );
531 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0 );
532 ensureResult.first.val().m_val = 5;
534 CPPUNIT_ASSERT( it != l.end() );
535 CPPUNIT_ASSERT( it.key() == 100 );
536 CPPUNIT_ASSERT( it.val().m_val == 5 );
538 CPPUNIT_ASSERT( !l.empty() );
541 ensureResult = l.ensure( 1000 );
542 CPPUNIT_ASSERT( ensureResult.second );
543 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
544 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0 );
545 ensureResult.first.val().m_val = 33;
546 ensureResult = l.ensure( 1000 );
547 CPPUNIT_ASSERT( !ensureResult.second );
548 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
549 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 33 );
553 CPPUNIT_ASSERT( l.empty() );
556 CPPUNIT_ASSERT( l.emplace( 501 ) != l.end());
557 CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
559 // insert failed - such key exists
560 CPPUNIT_ASSERT( l.emplace( 501, 2 ) == l.end());
561 CPPUNIT_ASSERT( l.emplace( 251, 10) == l.end());
564 CPPUNIT_ASSERT( it != l.end() );
565 CPPUNIT_ASSERT( it.key() == 501 );
566 CPPUNIT_ASSERT( it.val().m_val == 0 );
569 CPPUNIT_ASSERT( it != l.end() );
570 CPPUNIT_ASSERT( it.key() == 251 );
571 CPPUNIT_ASSERT( it.val().m_val == 152 );
574 CPPUNIT_ASSERT( l.empty() );
579 for ( int i = 0; i < nCount; ++i )
580 CPPUNIT_ASSERT( l.insert(i, i * 2 ) != l.end() );
583 typename OrdList::iterator it( l.begin() );
584 typename OrdList::const_iterator cit( l.cbegin() );
585 CPPUNIT_CHECK( it == cit );
586 CPPUNIT_CHECK( it != l.end() );
587 CPPUNIT_CHECK( it != l.cend() );
588 CPPUNIT_CHECK( cit != l.end() );
589 CPPUNIT_CHECK( cit != l.cend() );
591 CPPUNIT_CHECK( it != cit );
592 CPPUNIT_CHECK( it != l.end() );
593 CPPUNIT_CHECK( it != l.cend() );
594 CPPUNIT_CHECK( cit != l.end() );
595 CPPUNIT_CHECK( cit != l.cend() );
597 CPPUNIT_CHECK( it == cit );
598 CPPUNIT_CHECK( it != l.end() );
599 CPPUNIT_CHECK( it != l.cend() );
600 CPPUNIT_CHECK( cit != l.end() );
601 CPPUNIT_CHECK( cit != l.cend() );
605 for ( typename OrdList::iterator iter = l.begin(), itEnd = l.end(); iter != itEnd; ++iter, ++i ) {
606 CPPUNIT_ASSERT( iter.key() == i );
607 CPPUNIT_ASSERT( iter->first == i );
608 CPPUNIT_ASSERT( (*iter).first == i );
610 CPPUNIT_ASSERT( iter.val().m_val == i * 2 );
611 CPPUNIT_ASSERT( iter->second.m_val == i * 2 );
612 CPPUNIT_ASSERT( (*iter).second.m_val == i * 2 );
614 iter.val().m_val = i * 3;
617 // Check that we have visited all items
618 for ( int i = 0; i < nCount; ++i ) {
620 CPPUNIT_ASSERT( it != l.end() );
621 CPPUNIT_ASSERT( it.key() == i );
622 CPPUNIT_ASSERT( it.val().m_val == i * 3 );
626 CPPUNIT_ASSERT( l.empty() );
629 for ( int i = 0; i < nCount; ++i )
630 CPPUNIT_ASSERT( l.insert(i, i * 7) != l.end() );
633 const OrdList& rl = l;
634 for ( typename OrdList::const_iterator iter = rl.begin(), itEnd = rl.end(); iter != itEnd; ++iter, ++i ) {
635 CPPUNIT_ASSERT( iter.key() == i );
636 CPPUNIT_ASSERT( iter->first == i );
637 CPPUNIT_ASSERT( (*iter).first == i );
639 CPPUNIT_ASSERT( iter.val().m_val == i * 7 );
640 CPPUNIT_ASSERT( iter->second.m_val == i * 7 );
641 CPPUNIT_ASSERT( (*iter).second.m_val == i * 7 );
642 // it.val().m_val = i * 3 ; // error: const-iterator
646 CPPUNIT_ASSERT( l.empty() );
652 template <class UnordList>
653 void nogc_unord_test()
655 typedef typename UnordList::value_type value_type;
656 typedef typename UnordList::iterator iterator;
662 CPPUNIT_ASSERT( l.empty() );
664 // insert / find test
665 CPPUNIT_ASSERT( l.find( 100 ) == l.end() );
666 CPPUNIT_ASSERT( l.insert( 100 ) != l.end() );
667 CPPUNIT_ASSERT( !l.empty() );
669 CPPUNIT_ASSERT( it != l.end() );
670 CPPUNIT_ASSERT( it.key() == 100 );
671 CPPUNIT_ASSERT( it.val().m_val == 0 );
673 CPPUNIT_ASSERT( l.find_with( 50, eq<key_type>() ) == l.end() );
674 CPPUNIT_ASSERT( l.insert( 50, 500 ) != l.end());
676 CPPUNIT_ASSERT( it != l.end() );
677 CPPUNIT_ASSERT( it.key() == 50 );
678 CPPUNIT_ASSERT( it.val().m_val == 500 );
680 CPPUNIT_ASSERT( l.insert( 50, 5 ) == l.end() );
682 CPPUNIT_ASSERT( it != l.end() );
683 CPPUNIT_ASSERT( it.key() == 50 );
684 CPPUNIT_ASSERT( it.val().m_val == 500 );
685 CPPUNIT_ASSERT( !l.empty() );
687 CPPUNIT_ASSERT( l.find( 150 ) == l.end() );
688 CPPUNIT_ASSERT( l.insert_with( 150, insert_functor() ) != l.end() );
690 CPPUNIT_ASSERT( it != l.end() );
691 CPPUNIT_ASSERT( it.key() == 150 );
692 CPPUNIT_ASSERT( it.val().m_val == 1500 );
694 CPPUNIT_ASSERT( it != l.end() );
695 CPPUNIT_ASSERT( it.key() == 100 );
696 CPPUNIT_ASSERT( it.val().m_val == 0 );
698 CPPUNIT_ASSERT( it != l.end() );
699 CPPUNIT_ASSERT( it.key() == 50 );
700 CPPUNIT_ASSERT( it.val().m_val == 500 );
703 CPPUNIT_ASSERT( it != l.end() );
704 CPPUNIT_ASSERT( it.key() == 50 );
705 CPPUNIT_ASSERT( it.val().m_val == 25 );
706 CPPUNIT_ASSERT( !l.empty() );
708 // ensure existing item
709 std::pair<iterator, bool> ensureResult;
710 ensureResult = l.ensure( 100 );
711 CPPUNIT_ASSERT( !ensureResult.second );
712 CPPUNIT_ASSERT( ensureResult.first.key() == 100 );
713 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0 );
714 ensureResult.first.val().m_val = 5;
716 CPPUNIT_ASSERT( it != l.end() );
717 CPPUNIT_ASSERT( it.key() == 100 );
718 CPPUNIT_ASSERT( it.val().m_val == 5 );
720 CPPUNIT_ASSERT( !l.empty() );
723 ensureResult = l.ensure( 1000 );
724 CPPUNIT_ASSERT( ensureResult.second );
725 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
726 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 0 );
727 ensureResult.first.val().m_val = 33;
728 ensureResult = l.ensure( 1000 );
729 CPPUNIT_ASSERT( !ensureResult.second );
730 CPPUNIT_ASSERT( ensureResult.first.key() == 1000 );
731 CPPUNIT_ASSERT( ensureResult.first.val().m_val == 33 );
735 CPPUNIT_ASSERT( l.empty() );
738 CPPUNIT_ASSERT( l.emplace( 501 ) != l.end());
739 CPPUNIT_ASSERT( l.emplace( 251, 152 ) != l.end());
741 // insert failed - such key exists
742 CPPUNIT_ASSERT( l.emplace( 501, 2 ) == l.end());
743 CPPUNIT_ASSERT( l.emplace( 251, 10) == l.end());
746 CPPUNIT_ASSERT( it != l.end() );
747 CPPUNIT_ASSERT( it.key() == 501 );
748 CPPUNIT_ASSERT( it.val().m_val == 0 );
751 CPPUNIT_ASSERT( it != l.end() );
752 CPPUNIT_ASSERT( it.key() == 251 );
753 CPPUNIT_ASSERT( it.val().m_val == 152 );
756 CPPUNIT_ASSERT( l.empty() );
761 for ( int i = 0; i < nCount; ++i )
762 CPPUNIT_ASSERT( l.insert(i, i * 2 ) != l.end() );
765 typename UnordList::iterator it( l.begin() );
766 typename UnordList::const_iterator cit( l.cbegin() );
767 CPPUNIT_CHECK( it == cit );
768 CPPUNIT_CHECK( it != l.end() );
769 CPPUNIT_CHECK( it != l.cend() );
770 CPPUNIT_CHECK( cit != l.end() );
771 CPPUNIT_CHECK( cit != l.cend() );
773 CPPUNIT_CHECK( it != cit );
774 CPPUNIT_CHECK( it != l.end() );
775 CPPUNIT_CHECK( it != l.cend() );
776 CPPUNIT_CHECK( cit != l.end() );
777 CPPUNIT_CHECK( cit != l.cend() );
779 CPPUNIT_CHECK( it == cit );
780 CPPUNIT_CHECK( it != l.end() );
781 CPPUNIT_CHECK( it != l.cend() );
782 CPPUNIT_CHECK( cit != l.end() );
783 CPPUNIT_CHECK( cit != l.cend() );
787 for ( typename UnordList::iterator iter = l.begin(), itEnd = l.end(); iter != itEnd; ++iter, ++i ) {
788 CPPUNIT_ASSERT( iter.key() == i );
789 CPPUNIT_ASSERT( iter->first == i );
790 CPPUNIT_ASSERT( (*iter).first == i );
792 CPPUNIT_ASSERT( iter.val().m_val == i * 2 );
793 CPPUNIT_ASSERT( iter->second.m_val == i * 2 );
794 CPPUNIT_ASSERT( (*iter).second.m_val == i * 2 );
796 iter.val().m_val = i * 3;
799 // Check that we have visited all items
800 for ( int i = 0; i < nCount; ++i ) {
802 CPPUNIT_ASSERT( it != l.end() );
803 CPPUNIT_ASSERT( it.key() == i );
804 CPPUNIT_ASSERT( it.val().m_val == i * 3 );
808 CPPUNIT_ASSERT( l.empty() );
811 for ( int i = 0; i < nCount; ++i )
812 CPPUNIT_ASSERT( l.insert(i, i * 7) != l.end() );
815 const UnordList& rl = l;
816 for ( typename UnordList::const_iterator iter = rl.begin(), itEnd = rl.end(); iter != itEnd; ++iter, ++i ) {
817 CPPUNIT_ASSERT( iter.key() == i );
818 CPPUNIT_ASSERT( iter->first == i );
819 CPPUNIT_ASSERT( (*iter).first == i );
821 CPPUNIT_ASSERT( iter.val().m_val == i * 7 );
822 CPPUNIT_ASSERT( iter->second.m_val == i * 7 );
823 CPPUNIT_ASSERT( (*iter).second.m_val == i * 7 );
824 // it.val().m_val = i * 3 ; // error: const-iterator
828 CPPUNIT_ASSERT( l.empty() );
847 void RCU_GPI_cmpmix();
852 void RCU_GPB_cmpmix();
857 void RCU_GPT_cmpmix();
862 void RCU_SHB_cmpmix();
867 void RCU_SHT_cmpmix();
875 void NOGC_cmp_unord();
876 void NOGC_less_unord();
877 void NOGC_equal_to_unord();
878 void NOGC_cmpmix_unord();
879 void NOGC_ic_unord();
881 CPPUNIT_TEST_SUITE(LazyKVListTestHeader)
883 CPPUNIT_TEST(HP_less)
884 CPPUNIT_TEST(HP_cmpmix)
887 CPPUNIT_TEST(DHP_cmp)
888 CPPUNIT_TEST(DHP_less)
889 CPPUNIT_TEST(DHP_cmpmix)
892 CPPUNIT_TEST(RCU_GPI_cmp)
893 CPPUNIT_TEST(RCU_GPI_less)
894 CPPUNIT_TEST(RCU_GPI_cmpmix)
895 CPPUNIT_TEST(RCU_GPI_ic)
897 CPPUNIT_TEST(RCU_GPB_cmp)
898 CPPUNIT_TEST(RCU_GPB_less)
899 CPPUNIT_TEST(RCU_GPB_cmpmix)
900 CPPUNIT_TEST(RCU_GPB_ic)
902 CPPUNIT_TEST(RCU_GPT_cmp)
903 CPPUNIT_TEST(RCU_GPT_less)
904 CPPUNIT_TEST(RCU_GPT_cmpmix)
905 CPPUNIT_TEST(RCU_GPT_ic)
907 CPPUNIT_TEST(RCU_SHB_cmp)
908 CPPUNIT_TEST(RCU_SHB_less)
909 CPPUNIT_TEST(RCU_SHB_cmpmix)
910 CPPUNIT_TEST(RCU_SHB_ic)
912 CPPUNIT_TEST(RCU_SHT_cmp)
913 CPPUNIT_TEST(RCU_SHT_less)
914 CPPUNIT_TEST(RCU_SHT_cmpmix)
915 CPPUNIT_TEST(RCU_SHT_ic)
917 CPPUNIT_TEST(NOGC_cmp)
918 CPPUNIT_TEST(NOGC_less)
919 CPPUNIT_TEST(NOGC_cmpmix)
920 CPPUNIT_TEST(NOGC_ic)
922 CPPUNIT_TEST(NOGC_cmp_unord)
923 CPPUNIT_TEST(NOGC_less_unord)
924 CPPUNIT_TEST(NOGC_equal_to_unord)
925 CPPUNIT_TEST(NOGC_cmpmix_unord)
926 CPPUNIT_TEST(NOGC_ic_unord)
928 CPPUNIT_TEST_SUITE_END()
931 } // namespace ordlist
933 #endif // #ifndef CDSTEST_HDR_LAZY_KV_H