xref: /aoo41x/main/o3tl/qa/test-vector_pool.cxx (revision cdf0e10c)
1 // autogenerated file with codegen.pl
2 
3 #include "preextstl.h"
4 #include "cppunit/TestAssert.h"
5 #include "cppunit/TestFixture.h"
6 #include "cppunit/extensions/HelperMacros.h"
7 #include "postextstl.h"
8 
9 #include <o3tl/vector_pool.hxx>
10 
11 using namespace ::o3tl;
12 
13 class vector_pool_test : public CppUnit::TestFixture
14 {
15 public:
16     void testPoolBasics()
17     {
18         vector_pool<int> aPool;
19 
20         std::ptrdiff_t nIdx1 = aPool.alloc();
21         std::ptrdiff_t nIdx2 = aPool.alloc();
22         std::ptrdiff_t nIdx3 = aPool.alloc();
23 
24         CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
25         CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
26 
27         aPool.free(nIdx2);
28         aPool.free(nIdx3);
29 
30         nIdx2 = aPool.alloc();
31         nIdx3 = aPool.alloc();
32 
33         CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
34         CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
35     }
36 
37     void testPoolValueSemantics()
38     {
39         vector_pool<int> aPool;
40 
41         std::ptrdiff_t nIdx1 = aPool.store(0);
42         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
43 
44         std::ptrdiff_t nIdx2 = aPool.store(1);
45         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
46 
47         std::ptrdiff_t nIdx3 = aPool.store(2);
48         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
49 
50         aPool.free(nIdx2);
51         aPool.free(nIdx3);
52 
53         nIdx2 = aPool.store(1);
54         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
55 
56         nIdx3 = aPool.store(2);
57         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
58     }
59 
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.
63 
64     CPPUNIT_TEST_SUITE(vector_pool_test);
65     CPPUNIT_TEST(testPoolBasics);
66     CPPUNIT_TEST(testPoolValueSemantics);
67     CPPUNIT_TEST_SUITE_END();
68 };
69 
70 // -----------------------------------------------------------------------------
71 CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);
72