CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / o3tl / qa / test-vector_pool.cxx
blobab301752532ec45ed01e5c71081dd8a26d2f3a5f
1 // autogenerated file with codegen.pl
3 #include "preextstl.h"
4 #include "cppunit/TestAssert.h"
5 #include "cppunit/TestFixture.h"
6 #include "cppunit/extensions/HelperMacros.h"
7 #include "postextstl.h"
9 #include <o3tl/vector_pool.hxx>
11 using namespace ::o3tl;
13 class vector_pool_test : public CppUnit::TestFixture
15 public:
16 void testPoolBasics()
18 vector_pool<int> aPool;
20 std::ptrdiff_t nIdx1 = aPool.alloc();
21 std::ptrdiff_t nIdx2 = aPool.alloc();
22 std::ptrdiff_t nIdx3 = aPool.alloc();
24 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
25 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
27 aPool.free(nIdx2);
28 aPool.free(nIdx3);
30 nIdx2 = aPool.alloc();
31 nIdx3 = aPool.alloc();
33 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
34 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
37 void testPoolValueSemantics()
39 vector_pool<int> aPool;
41 std::ptrdiff_t nIdx1 = aPool.store(0);
42 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
44 std::ptrdiff_t nIdx2 = aPool.store(1);
45 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
47 std::ptrdiff_t nIdx3 = aPool.store(2);
48 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
50 aPool.free(nIdx2);
51 aPool.free(nIdx3);
53 nIdx2 = aPool.store(1);
54 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
56 nIdx3 = aPool.store(2);
57 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
60 // Change the following lines only, if you add, remove or rename
61 // member functions of the current class,
62 // because these macros are need by auto register mechanism.
64 CPPUNIT_TEST_SUITE(vector_pool_test);
65 CPPUNIT_TEST(testPoolBasics);
66 CPPUNIT_TEST(testPoolValueSemantics);
67 CPPUNIT_TEST_SUITE_END();
70 // -----------------------------------------------------------------------------
71 CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);