1*cdf0e10cSrcweir // autogenerated file with codegen.pl 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir #include "preextstl.h" 4*cdf0e10cSrcweir #include "cppunit/TestAssert.h" 5*cdf0e10cSrcweir #include "cppunit/TestFixture.h" 6*cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 7*cdf0e10cSrcweir #include "postextstl.h" 8*cdf0e10cSrcweir 9*cdf0e10cSrcweir #include <o3tl/vector_pool.hxx> 10*cdf0e10cSrcweir 11*cdf0e10cSrcweir using namespace ::o3tl; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir class vector_pool_test : public CppUnit::TestFixture 14*cdf0e10cSrcweir { 15*cdf0e10cSrcweir public: 16*cdf0e10cSrcweir void testPoolBasics() 17*cdf0e10cSrcweir { 18*cdf0e10cSrcweir vector_pool<int> aPool; 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir std::ptrdiff_t nIdx1 = aPool.alloc(); 21*cdf0e10cSrcweir std::ptrdiff_t nIdx2 = aPool.alloc(); 22*cdf0e10cSrcweir std::ptrdiff_t nIdx3 = aPool.alloc(); 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 ); 25*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 ); 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir aPool.free(nIdx2); 28*cdf0e10cSrcweir aPool.free(nIdx3); 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir nIdx2 = aPool.alloc(); 31*cdf0e10cSrcweir nIdx3 = aPool.alloc(); 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 ); 34*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 ); 35*cdf0e10cSrcweir } 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir void testPoolValueSemantics() 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir vector_pool<int> aPool; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir std::ptrdiff_t nIdx1 = aPool.store(0); 42*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 ); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir std::ptrdiff_t nIdx2 = aPool.store(1); 45*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 ); 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir std::ptrdiff_t nIdx3 = aPool.store(2); 48*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 ); 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir aPool.free(nIdx2); 51*cdf0e10cSrcweir aPool.free(nIdx3); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir nIdx2 = aPool.store(1); 54*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 ); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir nIdx3 = aPool.store(2); 57*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 ); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 61*cdf0e10cSrcweir // member functions of the current class, 62*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(vector_pool_test); 65*cdf0e10cSrcweir CPPUNIT_TEST(testPoolBasics); 66*cdf0e10cSrcweir CPPUNIT_TEST(testPoolValueSemantics); 67*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 71*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test); 72