LCOV - code coverage report
Current view: top level - libreoffice/o3tl/qa - test-vector_pool.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 35 100.0 %
Date: 2012-12-27 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include "cppunit/TestAssert.h"
      22             : #include "cppunit/TestFixture.h"
      23             : #include "cppunit/extensions/HelperMacros.h"
      24             : 
      25             : #include <o3tl/vector_pool.hxx>
      26             : 
      27             : using namespace ::o3tl;
      28             : 
      29           6 : class vector_pool_test : public CppUnit::TestFixture
      30             : {
      31             : public:
      32           1 :     void testPoolBasics()
      33             :     {
      34           1 :         vector_pool<int> aPool;
      35             : 
      36           1 :         std::ptrdiff_t nIdx1 = aPool.alloc();
      37           1 :         std::ptrdiff_t nIdx2 = aPool.alloc();
      38           1 :         std::ptrdiff_t nIdx3 = aPool.alloc();
      39             : 
      40           1 :         CPPUNIT_ASSERT_MESSAGE("allocator idx order 1", nIdx1 < nIdx2 );
      41           1 :         CPPUNIT_ASSERT_MESSAGE("allocator idx order 2", nIdx2 < nIdx3 );
      42             : 
      43           1 :         aPool.free(nIdx2);
      44           1 :         aPool.free(nIdx3);
      45             : 
      46           1 :         nIdx2 = aPool.alloc();
      47           1 :         nIdx3 = aPool.alloc();
      48             : 
      49           1 :         CPPUNIT_ASSERT_MESSAGE("allocator idx order 1 after fragmentation", nIdx1 < nIdx3 );
      50           1 :         CPPUNIT_ASSERT_MESSAGE("allocator idx order 2 after fragmentation", nIdx3 < nIdx2 );
      51           1 :     }
      52             : 
      53           1 :     void testPoolValueSemantics()
      54             :     {
      55           1 :         vector_pool<int> aPool;
      56             : 
      57           1 :         std::ptrdiff_t nIdx1 = aPool.store(0);
      58           1 :         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 1", aPool.get(nIdx1) == 0 );
      59             : 
      60           1 :         std::ptrdiff_t nIdx2 = aPool.store(1);
      61           1 :         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2", aPool.get(nIdx2) == 1 );
      62             : 
      63           1 :         std::ptrdiff_t nIdx3 = aPool.store(2);
      64           1 :         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3", aPool.get(nIdx3) == 2 );
      65             : 
      66           1 :         aPool.free(nIdx2);
      67           1 :         aPool.free(nIdx3);
      68             : 
      69           1 :         nIdx2 = aPool.store(1);
      70           1 :         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 2 after fragmentation", aPool.get(nIdx2) == 1 );
      71             : 
      72           1 :         nIdx3 = aPool.store(2);
      73           1 :         CPPUNIT_ASSERT_MESSAGE("allocator value semantics 3 after fragmentation", aPool.get(nIdx3) == 2 );
      74           1 :     }
      75             : 
      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.
      79             : 
      80           2 :     CPPUNIT_TEST_SUITE(vector_pool_test);
      81           1 :     CPPUNIT_TEST(testPoolBasics);
      82           1 :     CPPUNIT_TEST(testPoolValueSemantics);
      83           2 :     CPPUNIT_TEST_SUITE_END();
      84             : };
      85             : 
      86             : // -----------------------------------------------------------------------------
      87           3 : CPPUNIT_TEST_SUITE_REGISTRATION(vector_pool_test);
      88             : 
      89             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10