1e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott//Has to be first for StackAllocator swap overload to be taken 2e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott//into account (at least using GCC 4.0.1) 3e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "stack_allocator.h" 4e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 5e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include <list> 6e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include <algorithm> 7e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include <functional> 8e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 9e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "cppunit/cppunit_proxy.h" 10e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 11e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 12e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottusing namespace std; 13e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif 14e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 15e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// 16e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// TestCase class 17e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// 18e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass ListTest : public CPPUNIT_NS::TestCase 19e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 20e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST_SUITE(ListTest); 21e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(list1); 22e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(list2); 23e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(list3); 24e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(list4); 25e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(erase); 26e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(resize); 27e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(push_back); 28e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(push_front); 29e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(allocator_with_state); 30e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(swap); 31e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST(adl); 32e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //CPPUNIT_TEST(const_list); 33e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_TEST_SUITE_END(); 34e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 35e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottprotected: 36e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void list1(); 37e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void list2(); 38e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void list3(); 39e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void list4(); 40e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void erase(); 41e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void resize(); 42e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void push_back(); 43e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void push_front(); 44e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void allocator_with_state(); 45e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void swap(); 46e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott void adl(); 47e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //void const_list(); 48e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott}; 49e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 50e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick ScottCPPUNIT_TEST_SUITE_REGISTRATION(ListTest); 51e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 52e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// 53e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// tests implementation 54e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// 55e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::list1() 56e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 57e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array1 [] = { 9, 16, 36 }; 58e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array2 [] = { 1, 4 }; 59e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 60e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l1(array1, array1 + 3); 61e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l2(array2, array2 + 2); 62e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator i1 = l1.begin(); 63e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator i2 = l2.begin(); 64e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::const_iterator ci(i1); 65e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::const_iterator ci1(ci); 66e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l1.splice(i1, l2); 67e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i1 = l1.begin(); 68e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1++ == 1 ); 69e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1++ == 4 ); 70e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1++ == 9 ); 71e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1++ == 16 ); 72e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1++ == 36 ); 73e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 74e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#if defined (STLPORT) && \ 75e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott (!defined (_STLP_DEBUG) || (_STLP_DEBUG_LEVEL != _STLP_STANDARD_DBG_LEVEL)) 76e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( i2 == l1.begin() ); 77e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif 78e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 79e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //Default construct check (_STLP_DEF_CONST_PLCT_NEW_BUG) 80e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l(2); 81e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i1 = l.begin(); 82e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *(i1++) == 0 ); 83e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i1 == 0 ); 84e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#if 0 85e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //A small compilation time check to be activated from time to time, 86e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //compilation should fail. 87e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 88e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<char>::iterator l_char_ite; 89e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator l_int_ite; 90e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( l_char_ite != l_int_ite ); 91e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 92e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif 93e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 94e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 95e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::list2() 96e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 97e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array1 [] = { 1, 16 }; 98e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array2 [] = { 4, 9 }; 99e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 100e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l1(array1, array1 + 2); 101e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l2(array2, array2 + 2); 102e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator i = l1.begin(); 103e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i++; 104e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l1.splice(i, l2, l2.begin(), l2.end()); 105e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i = l1.begin(); 106e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==1); 107e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==4); 108e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==9); 109e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==16); 110e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 111e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 112e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::list3() 113e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 114e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott char array [] = { 'x', 'l', 'x', 't', 's', 's' }; 115e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 116e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<char> str(array, array + 6); 117e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<char>::iterator i; 118e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 119e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott str.reverse(); 120e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i = str.begin(); 121e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 122e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 123e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='t'); 124e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='x'); 125e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='l'); 126e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='x'); 127e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 128e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott str.remove('x'); 129e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i = str.begin(); 130e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 131e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 132e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='t'); 133e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='l'); 134e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 135e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott str.unique(); 136e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i = str.begin(); 137e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 138e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='t'); 139e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='l'); 140e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 141e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott str.sort(); 142e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott i = str.begin(); 143e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='l'); 144e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='s'); 145e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++=='t'); 146e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 147e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 148e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::list4() 149e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 150e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array1 [] = { 1, 3, 6, 7 }; 151e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array2 [] = { 2, 4 }; 152e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 153e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l1(array1, array1 + 4); 154e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l2(array2, array2 + 2); 155e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l1.merge(l2); 156e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator i = l1.begin(); 157e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==1); 158e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==2); 159e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==3); 160e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==4); 161e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==6); 162e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(*i++==7); 163e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 164e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //We use distance to avoid a simple call to an internal counter 165e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(distance(l1.begin(), l1.end()) == 6); 166e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(distance(l2.begin(), l2.end()) == 0); 167e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 168e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l1.swap(l2); 169e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 170e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(distance(l1.begin(), l1.end()) == 0); 171e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT(distance(l2.begin(), l2.end()) == 6); 172e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 173e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 174e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::erase() 175e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 176e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l; 177e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 1 ); 178e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.erase(l.begin()); 179e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( l.empty() ); 180e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 181e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott int array[] = { 0, 1, 2, 3 }; 182e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.assign(array, array + 4); 183e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator lit; 184e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lit = l.erase(l.begin()); 185e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *lit == 1 ); 186e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 187e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lit = l.erase(l.begin(), --l.end()); 188e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *lit == 3 ); 189e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 190e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.clear(); 191e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( l.empty() ); 192e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 193e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 194e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 195e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::resize() 196e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 197e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 198e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l; 199e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.resize(5, 1); 200e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 201e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott size_t i; 202e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator lit(l.begin()); 203e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott for (i = 0; i < 5; ++i) { 204e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit != l.end() ); 205e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *(lit++) == 1 ); 206e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 207e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit == l.end() ); 208e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 209e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.resize(3); 210e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lit = l.begin(); 211e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott for (i = 0; i < 3; ++i) { 212e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit != l.end() ); 213e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *(lit++) == 1 ); 214e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 215e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit == l.end() ); 216e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 217e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 218e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 219e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l; 220e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.resize(5); 221e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 222e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott size_t i; 223e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator lit(l.begin()); 224e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott for (i = 0; i < 5; ++i) { 225e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit != l.end() ); 226e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *(lit++) == 0 ); 227e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 228e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lit == l.end() ); 229e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 230e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 231e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 232e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::push_back() 233e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 234e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l; 235e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 1 ); 236e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 2 ); 237e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 3 ); 238e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 239e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::reverse_iterator r = l.rbegin(); 240e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 241e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *r == 3 ); 242e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 4 ); 243e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott /* 244e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * Following lines are commented, because ones show standard contradiction 245e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * (24.4.1 and 23.2.2.3); but present behaviour is valid, 24.4.1, paragraphs 1 and 2, 246e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * 24.4.1.3.3 and 23.1 paragraph 9 (Table 66). The 24.4.1 is more common rule, 247e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * so it has preference under 23.2.2.3, by my opinion. 248e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * 249e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * - ptr 250e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott */ 251e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott // CPPUNIT_ASSERT( *r == 3 ); 252e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott // ++r; 253e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott // CPPUNIT_ASSERT( *r == 2 ); 254e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 255e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 256e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::push_front() 257e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 258e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> l; 259e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 1 ); 260e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 2 ); 261e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_back( 3 ); 262e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 263e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int>::iterator i = l.begin(); 264e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 265e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i == 1 ); 266e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott l.push_front( 0 ); 267e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i == 1 ); 268e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ++i; 269e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( *i == 2 ); 270e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 271e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 272e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::allocator_with_state() 273e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 274e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott char buf1[1024]; 275e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); 276e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 277e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott char buf2[1024]; 278e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); 279e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 280e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott typedef list<int, StackAllocator<int> > ListInt; 281e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 282e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //Swap with both list non empty 283e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 284e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1Cpy(lint1); 285e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 286e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 1, stack2); 287e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2Cpy(lint2); 288e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 289e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.swap(lint2); 290e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 291e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); 292e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); 293e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 294e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1 == lint2Cpy ); 295e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2 == lint1Cpy ); 296e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); 297e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); 298e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 299e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 300e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 301e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 302e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 303e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 304e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //Swap with empty calle list 305e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 306e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1Cpy(lint1); 307e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 308e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(stack2); 309e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2Cpy(lint2); 310e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 311e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.swap(lint2); 312e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 313e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); 314e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); 315e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 316e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1 == lint2Cpy ); 317e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2 == lint1Cpy ); 318e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); 319e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); 320e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 321e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 322e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 323e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 324e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 325e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 326e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //Swap with empty caller list 327e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(stack1); 328e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1Cpy(lint1); 329e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 330e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 0, stack2); 331e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2Cpy(lint2); 332e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 333e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.swap(lint2); 334e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 335e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); 336e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); 337e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 338e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1 == lint2Cpy ); 339e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2 == lint1Cpy ); 340e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); 341e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); 342e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 343e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 344e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 345e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 346e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 347e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 348e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 349e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 1, stack2); 350e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 351e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.splice(lint1.begin(), lint2); 352e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.size() == 20 ); 353e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.empty() ); 354e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 355e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 356e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 357e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 358e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 359e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 360e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 361e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 1, stack2); 362e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 363e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.splice(lint1.begin(), lint2, lint2.begin()); 364e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.size() == 11 ); 365e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.size() == 9 ); 366e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 367e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 368e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 369e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 370e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 371e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 372e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 373e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 1, stack2); 374e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 375e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt::iterator lit(lint2.begin()); 376e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott advance(lit, 5); 377e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.splice(lint1.begin(), lint2, lint2.begin(), lit); 378e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.size() == 15 ); 379e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.size() == 5 ); 380e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 381e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 382e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 383e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott stack1.reset(); stack2.reset(); 384e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 385e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 386e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 387e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint2(10, 1, stack2); 388e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 389e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lintref(stack2); 390e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lintref.insert(lintref.begin(), 10, 1); 391e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lintref.insert(lintref.begin(), 10, 0); 392e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 393e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.merge(lint2); 394e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1.size() == 20 ); 395e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint1 == lintref ); 396e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lint2.empty() ); 397e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 398e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack1.ok() ); 399e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( stack2.ok() ); 400e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 401e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#if defined (STLPORT) && !defined (_STLP_NO_MEMBER_TEMPLATES) && \ 402e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott (!defined (_MSC_VER) || (_MSC_VER >= 1300)) 403e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott { 404e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //This is a compile time test. 405e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //We check that sort implementation is correct when list is instanciated 406e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott //with an allocator that do not have a default constructor. 407e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott ListInt lint1(10, 0, stack1); 408e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.sort(); 409e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lint1.sort(greater<int>()); 410e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott } 411e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif 412e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 413e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 414e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott/* 415e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::const_list() 416e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 417e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<const int> cint_list; 418e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott cint_list.push_back(1); 419e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott cint_list.push_front(2); 420e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 421e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott*/ 422e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::swap() 423e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 424e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> lst1; 425e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<int> lst2; 426e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 427e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lst1.push_back(1); 428e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lst2.push_back(2); 429e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 430e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lst1.swap( lst2 ); 431e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 432e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst1.front() == 2 ); 433e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst2.front() == 1 ); 434e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst1.size() == 1 ); 435e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst2.size() == 1 ); 436e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 437e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lst1.pop_front(); 438e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott lst2.pop_front(); 439e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 440e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst1.empty() ); 441e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_CHECK( lst2.empty() ); 442e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 443e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 444e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottnamespace foo { 445e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott class bar {}; 446e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 447e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott template <class _It> 448e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott size_t distance(_It, _It); 449e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 450e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 451e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottvoid ListTest::adl() 452e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 453e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<foo::bar> lbar; 454e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott CPPUNIT_ASSERT( lbar.size() == 0); 455e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott} 456e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 457e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#if !defined (STLPORT) || \ 458e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) 459e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott/* Simple compilation test: Check that nested types like iterator 460e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * can be access even if type used to instanciate container is not 461e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott * yet completely defined. 462e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott */ 463e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass IncompleteClass 464e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ 465e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott list<IncompleteClass> instances; 466e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott typedef list<IncompleteClass>::iterator it; 467e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott}; 468e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif 469