LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/rtl/alloc - rtl_alloc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 55 98.2 %
Date: 2012-12-27 Functions: 23 24 95.8 %
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 <rtl/alloc.h>
      21             : #include <sal/types.h>
      22             : #include <cppunit/TestFixture.h>
      23             : #include <cppunit/extensions/HelperMacros.h>
      24             : #include <cppunit/plugin/TestPlugIn.h>
      25             : 
      26             : #include <memory.h>
      27             : 
      28             : namespace rtl_alloc
      29             : {
      30             : 
      31             :     // small memory check routine, which return false, if there is a problem
      32             : 
      33           4 :     bool checkMemory(char* _pMemory, sal_uInt32 _nSize, char _n)
      34             :     {
      35           4 :         bool bOk = true;
      36             : 
      37   104860676 :         for (sal_uInt32 i=0;i<_nSize;i++)
      38             :         {
      39   104860672 :             if (_pMemory[i] != _n)
      40             :             {
      41           0 :                 bOk = false;
      42             :             }
      43             :         }
      44           4 :         return bOk;
      45             :     }
      46             : 
      47           4 : class Memory : public CppUnit::TestFixture
      48             : {
      49             :     // for normal alloc functions
      50             :     char       *m_pMemory;
      51             :     sal_uInt32  m_nSizeOfMemory;
      52             : 
      53             : public:
      54           2 :     Memory()
      55             :         : m_pMemory(NULL)
      56           2 :         , m_nSizeOfMemory(1024)
      57             :     {
      58           2 :     }
      59             : 
      60             :     // initialise your test code values here.
      61           2 :     void setUp()
      62             :     {
      63           2 :         m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory );
      64           2 :     }
      65             : 
      66           2 :     void tearDown()
      67             :     {
      68           2 :         rtl_freeMemory(m_pMemory);
      69           2 :         m_pMemory = NULL;
      70           2 :     }
      71             : 
      72           1 :     void rtl_allocateMemory_001()
      73             :     {
      74           1 :         CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL);
      75           1 :         memset(m_pMemory, 1, m_nSizeOfMemory);
      76           1 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true);
      77           1 :     }
      78             : 
      79           1 :     void rtl_reallocateMemory_001()
      80             :     {
      81           1 :         sal_uInt32 nSize = 2 * 1024;
      82           1 :         m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize);
      83             : 
      84           1 :         CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL);
      85           1 :         memset(m_pMemory, 2, nSize);
      86           1 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true);
      87           1 :     }
      88             : 
      89           2 :     CPPUNIT_TEST_SUITE(Memory);
      90           1 :     CPPUNIT_TEST(rtl_allocateMemory_001);
      91           1 :     CPPUNIT_TEST(rtl_reallocateMemory_001);
      92           2 :     CPPUNIT_TEST_SUITE_END();
      93             : }; // class test
      94             : 
      95           2 : class TestZeroMemory : public CppUnit::TestFixture
      96             : {
      97             :     // for zero functions
      98             :     char       *m_pZeroMemory;
      99             :     sal_uInt32  m_nSizeOfZeroMemory;
     100             : 
     101             : public:
     102           1 :     TestZeroMemory()
     103             :         : m_pZeroMemory(NULL)
     104           1 :         , m_nSizeOfZeroMemory( 50 * 1024 * 1024 )
     105             :     {
     106           1 :     }
     107             : 
     108             :     // initialise your test code values here.
     109           1 :     void setUp()
     110             :     {
     111           1 :         m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory );
     112           1 :     }
     113             : 
     114           1 :     void tearDown()
     115             :     {
     116           1 :         rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory);
     117             :         // LLA: no check possible, may GPF if there is something wrong.
     118             :         // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL);
     119           1 :     }
     120             : 
     121             :     // insert your test code here.
     122             : 
     123           1 :     void rtl_allocateZeroMemory_001()
     124             :     {
     125           1 :         CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != NULL);
     126           1 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true);
     127             : 
     128           1 :         memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory);
     129           1 :         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true);
     130           1 :     }
     131             : 
     132           2 :     CPPUNIT_TEST_SUITE(TestZeroMemory);
     133           1 :     CPPUNIT_TEST(rtl_allocateZeroMemory_001);
     134           2 :     CPPUNIT_TEST_SUITE_END();
     135             : };
     136             : 
     137             : // -----------------------------------------------------------------------------
     138           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::Memory);
     139           1 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestZeroMemory);
     140             : } // namespace rtl_alloc
     141             : 
     142             : 
     143           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10