LCOV - code coverage report
Current view: top level - sal/qa/rtl/alloc - rtl_alloc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 55 98.2 %
Date: 2012-08-25 Functions: 23 24 95.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 117 238 49.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <rtl/alloc.h>
      30                 :            : #include <sal/types.h>
      31                 :            : #include <cppunit/TestFixture.h>
      32                 :            : #include <cppunit/extensions/HelperMacros.h>
      33                 :            : #include <cppunit/plugin/TestPlugIn.h>
      34                 :            : 
      35                 :            : #include <memory.h>
      36                 :            : 
      37                 :            : namespace rtl_alloc
      38                 :            : {
      39                 :            : 
      40                 :            :     // small memory check routine, which return false, if there is a problem
      41                 :            : 
      42                 :         20 :     bool checkMemory(char* _pMemory, sal_uInt32 _nSize, char _n)
      43                 :            :     {
      44                 :         20 :         bool bOk = true;
      45                 :            : 
      46         [ +  + ]:  524303380 :         for (sal_uInt32 i=0;i<_nSize;i++)
      47                 :            :         {
      48         [ -  + ]:  524303360 :             if (_pMemory[i] != _n)
      49                 :            :             {
      50                 :          0 :                 bOk = false;
      51                 :            :             }
      52                 :            :         }
      53                 :         20 :         return bOk;
      54                 :            :     }
      55                 :            : 
      56         [ -  + ]:         20 : class Memory : public CppUnit::TestFixture
      57                 :            : {
      58                 :            :     // for normal alloc functions
      59                 :            :     char       *m_pMemory;
      60                 :            :     sal_uInt32  m_nSizeOfMemory;
      61                 :            : 
      62                 :            : public:
      63                 :         10 :     Memory()
      64                 :            :         : m_pMemory(NULL)
      65                 :         10 :         , m_nSizeOfMemory(1024)
      66                 :            :     {
      67                 :         10 :     }
      68                 :            : 
      69                 :            :     // initialise your test code values here.
      70                 :         10 :     void setUp()
      71                 :            :     {
      72                 :         10 :         m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory );
      73                 :         10 :     }
      74                 :            : 
      75                 :         10 :     void tearDown()
      76                 :            :     {
      77                 :         10 :         rtl_freeMemory(m_pMemory);
      78                 :         10 :         m_pMemory = NULL;
      79                 :         10 :     }
      80                 :            : 
      81                 :          5 :     void rtl_allocateMemory_001()
      82                 :            :     {
      83 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      84                 :          5 :         memset(m_pMemory, 1, m_nSizeOfMemory);
      85 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      86                 :          5 :     }
      87                 :            : 
      88                 :          5 :     void rtl_reallocateMemory_001()
      89                 :            :     {
      90                 :          5 :         sal_uInt32 nSize = 2 * 1024;
      91                 :          5 :         m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize);
      92                 :            : 
      93 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      94                 :          5 :         memset(m_pMemory, 2, nSize);
      95 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      96                 :          5 :     }
      97                 :            : 
      98 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(Memory);
         [ +  - ][ +  - ]
                 [ #  # ]
      99 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(rtl_allocateMemory_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     100 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(rtl_reallocateMemory_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     101 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     102                 :            : }; // class test
     103                 :            : 
     104         [ -  + ]:         10 : class TestZeroMemory : public CppUnit::TestFixture
     105                 :            : {
     106                 :            :     // for zero functions
     107                 :            :     char       *m_pZeroMemory;
     108                 :            :     sal_uInt32  m_nSizeOfZeroMemory;
     109                 :            : 
     110                 :            : public:
     111                 :          5 :     TestZeroMemory()
     112                 :            :         : m_pZeroMemory(NULL)
     113                 :          5 :         , m_nSizeOfZeroMemory( 50 * 1024 * 1024 )
     114                 :            :     {
     115                 :          5 :     }
     116                 :            : 
     117                 :            :     // initialise your test code values here.
     118                 :          5 :     void setUp()
     119                 :            :     {
     120                 :          5 :         m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory );
     121                 :          5 :     }
     122                 :            : 
     123                 :          5 :     void tearDown()
     124                 :            :     {
     125                 :          5 :         rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory);
     126                 :            :         // LLA: no check possible, may GPF if there is something wrong.
     127                 :            :         // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL);
     128                 :          5 :     }
     129                 :            : 
     130                 :            :     // insert your test code here.
     131                 :            : 
     132                 :          5 :     void rtl_allocateZeroMemory_001()
     133                 :            :     {
     134 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != NULL);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     135 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     136                 :            : 
     137                 :          5 :         memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory);
     138 [ +  - ][ +  - ]:          5 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     139                 :          5 :     }
     140                 :            : 
     141 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(TestZeroMemory);
         [ +  - ][ +  - ]
                 [ #  # ]
     142 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(rtl_allocateZeroMemory_001);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     143 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     144                 :            : };
     145                 :            : 
     146                 :            : // -----------------------------------------------------------------------------
     147                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::Memory);
     148                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestZeroMemory);
     149                 :            : } // namespace rtl_alloc
     150                 :            : 
     151                 :            : 
     152 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     153                 :            : 
     154                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10