1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <o3tl/vector_pool.hxx>
26 using namespace ::o3tl
;
28 class vector_pool_test
: public CppUnit::TestFixture
33 vector_pool
<int> aPool
;
35 std::ptrdiff_t nIdx1
= aPool
.alloc();
36 std::ptrdiff_t nIdx2
= aPool
.alloc();
37 std::ptrdiff_t nIdx3
= aPool
.alloc();
39 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1
< nIdx2
);
40 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2
< nIdx3
);
45 nIdx2
= aPool
.alloc();
46 nIdx3
= aPool
.alloc();
48 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1
< nIdx3
);
49 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3
< nIdx2
);
52 void testPoolValueSemantics()
54 vector_pool
<int> aPool
;
56 std::ptrdiff_t nIdx1
= aPool
.store(0);
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("allocator value semantics 1", 0, aPool
.get(nIdx1
) );
59 std::ptrdiff_t nIdx2
= aPool
.store(1);
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("allocator value semantics 2", 1, aPool
.get(nIdx2
) );
62 std::ptrdiff_t nIdx3
= aPool
.store(2);
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("allocator value semantics 3", 2, aPool
.get(nIdx3
) );
68 nIdx2
= aPool
.store(1);
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("allocator value semantics 2 after fragmentation", 1, aPool
.get(nIdx2
) );
71 nIdx3
= aPool
.store(2);
72 CPPUNIT_ASSERT_EQUAL_MESSAGE("allocator value semantics 3 after fragmentation", 2, aPool
.get(nIdx3
) );
75 // Change the following lines only, if you add, remove or rename
76 // member functions of the current class,
77 // because these macros are need by auto register mechanism.
79 CPPUNIT_TEST_SUITE(vector_pool_test
);
80 CPPUNIT_TEST(testPoolBasics
);
81 CPPUNIT_TEST(testPoolValueSemantics
);
82 CPPUNIT_TEST_SUITE_END();
86 CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test
);
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */