131682d32SAndrew Rist /************************************************************** 231682d32SAndrew Rist * 331682d32SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 431682d32SAndrew Rist * or more contributor license agreements. See the NOTICE file 531682d32SAndrew Rist * distributed with this work for additional information 631682d32SAndrew Rist * regarding copyright ownership. The ASF licenses this file 731682d32SAndrew Rist * to you under the Apache License, Version 2.0 (the 831682d32SAndrew Rist * "License"); you may not use this file except in compliance 931682d32SAndrew Rist * with the License. You may obtain a copy of the License at 1031682d32SAndrew Rist * 1131682d32SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1231682d32SAndrew Rist * 1331682d32SAndrew Rist * Unless required by applicable law or agreed to in writing, 1431682d32SAndrew Rist * software distributed under the License is distributed on an 1531682d32SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1631682d32SAndrew Rist * KIND, either express or implied. See the License for the 1731682d32SAndrew Rist * specific language governing permissions and limitations 1831682d32SAndrew Rist * under the License. 1931682d32SAndrew Rist * 2031682d32SAndrew Rist *************************************************************/ 2131682d32SAndrew Rist 22cdf0e10cSrcweir // autogenerated file with codegen.pl 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "preextstl.h" 25*18cf0442SDamjan Jovanovic #include "gtest/gtest.h" 26cdf0e10cSrcweir #include "postextstl.h" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <o3tl/vector_pool.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir using namespace ::o3tl; 31cdf0e10cSrcweir 32*18cf0442SDamjan Jovanovic class vector_pool_test : public ::testing::Test 33cdf0e10cSrcweir { 34cdf0e10cSrcweir public: 35*18cf0442SDamjan Jovanovic }; 36cdf0e10cSrcweir TEST_F(vector_pool_test,testPoolBasics)37*18cf0442SDamjan JovanovicTEST_F(vector_pool_test, testPoolBasics) 38*18cf0442SDamjan Jovanovic { 39*18cf0442SDamjan Jovanovic vector_pool<int> aPool; 40cdf0e10cSrcweir 41*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx1 = aPool.alloc(); 42*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx2 = aPool.alloc(); 43*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx3 = aPool.alloc(); 44cdf0e10cSrcweir 45*18cf0442SDamjan Jovanovic ASSERT_TRUE(nIdx1 < nIdx2) << "allocator idx order 1"; 46*18cf0442SDamjan Jovanovic ASSERT_TRUE(nIdx2 < nIdx3) << "allocator idx order 2"; 47cdf0e10cSrcweir 48*18cf0442SDamjan Jovanovic aPool.free(nIdx2); 49*18cf0442SDamjan Jovanovic aPool.free(nIdx3); 50cdf0e10cSrcweir 51*18cf0442SDamjan Jovanovic nIdx2 = aPool.alloc(); 52*18cf0442SDamjan Jovanovic nIdx3 = aPool.alloc(); 53cdf0e10cSrcweir 54*18cf0442SDamjan Jovanovic ASSERT_TRUE(nIdx1 < nIdx3) << "allocator idx order 1 after fragmentation"; 55*18cf0442SDamjan Jovanovic ASSERT_TRUE(nIdx3 < nIdx2) << "allocator idx order 2 after fragmentation"; 56*18cf0442SDamjan Jovanovic } 57cdf0e10cSrcweir TEST_F(vector_pool_test,testPoolValueSemantics)58*18cf0442SDamjan JovanovicTEST_F(vector_pool_test, testPoolValueSemantics) 59*18cf0442SDamjan Jovanovic { 60*18cf0442SDamjan Jovanovic vector_pool<int> aPool; 61cdf0e10cSrcweir 62*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx1 = aPool.store(0); 63*18cf0442SDamjan Jovanovic ASSERT_TRUE(aPool.get(nIdx1) == 0) << "allocator value semantics 1"; 64cdf0e10cSrcweir 65*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx2 = aPool.store(1); 66*18cf0442SDamjan Jovanovic ASSERT_TRUE(aPool.get(nIdx2) == 1) << "allocator value semantics 2"; 67cdf0e10cSrcweir 68*18cf0442SDamjan Jovanovic std::ptrdiff_t nIdx3 = aPool.store(2); 69*18cf0442SDamjan Jovanovic ASSERT_TRUE(aPool.get(nIdx3) == 2) << "allocator value semantics 3"; 70cdf0e10cSrcweir 71*18cf0442SDamjan Jovanovic aPool.free(nIdx2); 72*18cf0442SDamjan Jovanovic aPool.free(nIdx3); 73cdf0e10cSrcweir 74*18cf0442SDamjan Jovanovic nIdx2 = aPool.store(1); 75*18cf0442SDamjan Jovanovic ASSERT_TRUE(aPool.get(nIdx2) == 1) << "allocator value semantics 2 after fragmentation"; 76cdf0e10cSrcweir 77*18cf0442SDamjan Jovanovic nIdx3 = aPool.store(2); 78*18cf0442SDamjan Jovanovic ASSERT_TRUE(aPool.get(nIdx3) == 2) << "allocator value semantics 3 after fragmentation"; 79*18cf0442SDamjan Jovanovic } 80cdf0e10cSrcweir 81