1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 30*cdf0e10cSrcweir #include "precompiled_sal.hxx" 31*cdf0e10cSrcweir // autogenerated file with codegen.pl 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/alloc.h> 34*cdf0e10cSrcweir #include <testshl/simpleheader.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace rtl_alloc 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // small memory check routine, which return false, if there is a problem 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir bool checkMemory(char* _pMemory, sal_uInt32 _nSize, char _n) 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir bool bOk = true; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir for (sal_uInt32 i=0;i<_nSize;i++) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir if (_pMemory[i] != _n) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir bOk = false; 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir return bOk; 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class Memory : public CppUnit::TestFixture 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir // for normal alloc functions 58*cdf0e10cSrcweir char *m_pMemory; 59*cdf0e10cSrcweir sal_uInt32 m_nSizeOfMemory; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir public: 62*cdf0e10cSrcweir Memory() 63*cdf0e10cSrcweir :m_pMemory(NULL), 64*cdf0e10cSrcweir m_nSizeOfMemory(50 * 1024 * 1024) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // initialise your test code values here. 69*cdf0e10cSrcweir void setUp() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir t_print("allocate memory\n"); 72*cdf0e10cSrcweir m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory ); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir void tearDown() 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir t_print("free memory\n"); 78*cdf0e10cSrcweir rtl_freeMemory(m_pMemory); 79*cdf0e10cSrcweir m_pMemory = NULL; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // insert your test code here. 83*cdf0e10cSrcweir void rtl_allocateMemory_001() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir // this is demonstration code 86*cdf0e10cSrcweir // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL); 89*cdf0e10cSrcweir memset(m_pMemory, 1, m_nSizeOfMemory); 90*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void rtl_reallocateMemory_001() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir t_print("reallocate memory\n"); 96*cdf0e10cSrcweir sal_uInt32 nSize = 10 * 1024 * 1024; 97*cdf0e10cSrcweir m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL); 100*cdf0e10cSrcweir memset(m_pMemory, 2, nSize); 101*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // void rtl_freeMemory_001() 105*cdf0e10cSrcweir // { 106*cdf0e10cSrcweir // // CPPUNIT_ASSERT_STUB(); 107*cdf0e10cSrcweir // } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 110*cdf0e10cSrcweir // member functions of the current class, 111*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(Memory); 114*cdf0e10cSrcweir CPPUNIT_TEST(rtl_allocateMemory_001); 115*cdf0e10cSrcweir CPPUNIT_TEST(rtl_reallocateMemory_001); 116*cdf0e10cSrcweir // CPPUNIT_TEST(rtl_freeMemory_001); 117*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 118*cdf0e10cSrcweir }; // class test 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir class ZeroMemory : public CppUnit::TestFixture 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir // for zero functions 123*cdf0e10cSrcweir char *m_pZeroMemory; 124*cdf0e10cSrcweir sal_uInt32 m_nSizeOfZeroMemory; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir public: 127*cdf0e10cSrcweir ZeroMemory() 128*cdf0e10cSrcweir :m_pZeroMemory(NULL), 129*cdf0e10cSrcweir m_nSizeOfZeroMemory( 50 * 1024 * 1024 ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // initialise your test code values here. 134*cdf0e10cSrcweir void setUp() 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir t_print("allocate zero memory\n"); 137*cdf0e10cSrcweir m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir void tearDown() 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir t_print("free zero memory\n"); 143*cdf0e10cSrcweir rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory); 144*cdf0e10cSrcweir // LLA: no check possible, may GPF if there is something wrong. 145*cdf0e10cSrcweir // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // insert your test code here. 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir void rtl_allocateZeroMemory_001() 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != NULL); 153*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory); 156*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 160*cdf0e10cSrcweir // member functions of the current class, 161*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(ZeroMemory); 164*cdf0e10cSrcweir CPPUNIT_TEST(rtl_allocateZeroMemory_001); 165*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 166*cdf0e10cSrcweir }; // class test 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 169*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::Memory, "rtl_alloc"); 170*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::ZeroMemory, "rtl_alloc"); 171*cdf0e10cSrcweir } // namespace rtl_alloc 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 177*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 178*cdf0e10cSrcweir NOADDITIONAL; 179*cdf0e10cSrcweir 180