GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / o3tl / qa / test-vector_pool.cxx
blob1b7ca1c97197ff3e1ab3e6809e9503204b2bb943
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/types.h>
21 #include "cppunit/TestAssert.h"
22 #include "cppunit/TestFixture.h"
23 #include "cppunit/extensions/HelperMacros.h"
25 #include <o3tl/vector_pool.hxx>
27 using namespace ::o3tl;
29 class vector_pool_test : public CppUnit::TestFixture
31 public:
32 void testPoolBasics()
34 vector_pool<int> aPool;
36 std::ptrdiff_t nIdx1 = aPool.alloc();
37 std::ptrdiff_t nIdx2 = aPool.alloc();
38 std::ptrdiff_t nIdx3 = aPool.alloc();
40 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
41 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
43 aPool.free(nIdx2);
44 aPool.free(nIdx3);
46 nIdx2 = aPool.alloc();
47 nIdx3 = aPool.alloc();
49 CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
50 CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
53 void testPoolValueSemantics()
55 vector_pool<int> aPool;
57 std::ptrdiff_t nIdx1 = aPool.store(0);
58 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
60 std::ptrdiff_t nIdx2 = aPool.store(1);
61 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
63 std::ptrdiff_t nIdx3 = aPool.store(2);
64 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
66 aPool.free(nIdx2);
67 aPool.free(nIdx3);
69 nIdx2 = aPool.store(1);
70 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
72 nIdx3 = aPool.store(2);
73 CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
76 // Change the following lines only, if you add, remove or rename
77 // member functions of the current class,
78 // because these macros are need by auto register mechanism.
80 CPPUNIT_TEST_SUITE(vector_pool_test);
81 CPPUNIT_TEST(testPoolBasics);
82 CPPUNIT_TEST(testPoolValueSemantics);
83 CPPUNIT_TEST_SUITE_END();
86 // -----------------------------------------------------------------------------
87 CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */