1*31682d32SAndrew Rist /************************************************************** 2*31682d32SAndrew Rist * 3*31682d32SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*31682d32SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*31682d32SAndrew Rist * distributed with this work for additional information 6*31682d32SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*31682d32SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*31682d32SAndrew Rist * "License"); you may not use this file except in compliance 9*31682d32SAndrew Rist * with the License. You may obtain a copy of the License at 10*31682d32SAndrew Rist * 11*31682d32SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*31682d32SAndrew Rist * 13*31682d32SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*31682d32SAndrew Rist * software distributed under the License is distributed on an 15*31682d32SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*31682d32SAndrew Rist * KIND, either express or implied. See the License for the 17*31682d32SAndrew Rist * specific language governing permissions and limitations 18*31682d32SAndrew Rist * under the License. 19*31682d32SAndrew Rist * 20*31682d32SAndrew Rist *************************************************************/ 21*31682d32SAndrew Rist 22cdf0e10cSrcweir // autogenerated file with codegen.pl 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "preextstl.h" 25cdf0e10cSrcweir #include "cppunit/TestAssert.h" 26cdf0e10cSrcweir #include "cppunit/TestFixture.h" 27cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 28cdf0e10cSrcweir #include "postextstl.h" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <o3tl/vector_pool.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace ::o3tl; 33cdf0e10cSrcweir 34cdf0e10cSrcweir class vector_pool_test : public CppUnit::TestFixture 35cdf0e10cSrcweir { 36cdf0e10cSrcweir public: testPoolBasics()37cdf0e10cSrcweir void testPoolBasics() 38cdf0e10cSrcweir { 39cdf0e10cSrcweir vector_pool<int> aPool; 40cdf0e10cSrcweir 41cdf0e10cSrcweir std::ptrdiff_t nIdx1 = aPool.alloc(); 42cdf0e10cSrcweir std::ptrdiff_t nIdx2 = aPool.alloc(); 43cdf0e10cSrcweir std::ptrdiff_t nIdx3 = aPool.alloc(); 44cdf0e10cSrcweir 45cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 ); 46cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 ); 47cdf0e10cSrcweir 48cdf0e10cSrcweir aPool.free(nIdx2); 49cdf0e10cSrcweir aPool.free(nIdx3); 50cdf0e10cSrcweir 51cdf0e10cSrcweir nIdx2 = aPool.alloc(); 52cdf0e10cSrcweir nIdx3 = aPool.alloc(); 53cdf0e10cSrcweir 54cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 ); 55cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 ); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir testPoolValueSemantics()58cdf0e10cSrcweir void testPoolValueSemantics() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir vector_pool<int> aPool; 61cdf0e10cSrcweir 62cdf0e10cSrcweir std::ptrdiff_t nIdx1 = aPool.store(0); 63cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir std::ptrdiff_t nIdx2 = aPool.store(1); 66cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir std::ptrdiff_t nIdx3 = aPool.store(2); 69cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir aPool.free(nIdx2); 72cdf0e10cSrcweir aPool.free(nIdx3); 73cdf0e10cSrcweir 74cdf0e10cSrcweir nIdx2 = aPool.store(1); 75cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir nIdx3 = aPool.store(2); 78cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 82cdf0e10cSrcweir // member functions of the current class, 83cdf0e10cSrcweir // because these macros are need by auto register mechanism. 84cdf0e10cSrcweir 85cdf0e10cSrcweir CPPUNIT_TEST_SUITE(vector_pool_test); 86cdf0e10cSrcweir CPPUNIT_TEST(testPoolBasics); 87cdf0e10cSrcweir CPPUNIT_TEST(testPoolValueSemantics); 88cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 89cdf0e10cSrcweir }; 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ----------------------------------------------------------------------------- 92cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test); 93