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