xref: /aoo41x/main/sal/qa/rtl/alloc/rtl_alloc.cxx (revision 79aad27f)
1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*87d2adbcSAndrew Rist  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*87d2adbcSAndrew Rist  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19*87d2adbcSAndrew Rist  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir // autogenerated file with codegen.pl
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <rtl/alloc.h>
30cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace rtl_alloc
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir     // small memory check routine, which return false, if there is a problem
36cdf0e10cSrcweir 
checkMemory(char * _pMemory,sal_uInt32 _nSize,char _n)37cdf0e10cSrcweir     bool checkMemory(char* _pMemory, sal_uInt32 _nSize, char _n)
38cdf0e10cSrcweir     {
39cdf0e10cSrcweir         bool bOk = true;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir         for (sal_uInt32 i=0;i<_nSize;i++)
42cdf0e10cSrcweir         {
43cdf0e10cSrcweir             if (_pMemory[i] != _n)
44cdf0e10cSrcweir             {
45cdf0e10cSrcweir                 bOk = false;
46cdf0e10cSrcweir             }
47cdf0e10cSrcweir         }
48cdf0e10cSrcweir         return bOk;
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class Memory : public CppUnit::TestFixture
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     // for normal alloc functions
54cdf0e10cSrcweir     char       *m_pMemory;
55cdf0e10cSrcweir     sal_uInt32  m_nSizeOfMemory;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir public:
Memory()58cdf0e10cSrcweir     Memory()
59cdf0e10cSrcweir             :m_pMemory(NULL),
60cdf0e10cSrcweir              m_nSizeOfMemory(50 * 1024 * 1024)
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // initialise your test code values here.
setUp()65cdf0e10cSrcweir     void setUp()
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir             t_print("allocate memory\n");
68cdf0e10cSrcweir             m_pMemory = (char*) rtl_allocateMemory( m_nSizeOfMemory );
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
tearDown()71cdf0e10cSrcweir     void tearDown()
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir             t_print("free memory\n");
74cdf0e10cSrcweir             rtl_freeMemory(m_pMemory);
75cdf0e10cSrcweir             m_pMemory = NULL;
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     // insert your test code here.
rtl_allocateMemory_001()79cdf0e10cSrcweir     void rtl_allocateMemory_001()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         // this is demonstration code
82cdf0e10cSrcweir         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory != NULL);
85cdf0e10cSrcweir         memset(m_pMemory, 1, m_nSizeOfMemory);
86cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, m_nSizeOfMemory, 1) == true);
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
rtl_reallocateMemory_001()89cdf0e10cSrcweir     void rtl_reallocateMemory_001()
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         t_print("reallocate memory\n");
92cdf0e10cSrcweir         sal_uInt32 nSize = 10 * 1024 * 1024;
93cdf0e10cSrcweir         m_pMemory = (char*)rtl_reallocateMemory(m_pMemory, nSize);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory != NULL);
96cdf0e10cSrcweir         memset(m_pMemory, 2, nSize);
97cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory, nSize, 2) == true);
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     // void rtl_freeMemory_001()
101cdf0e10cSrcweir     //     {
102cdf0e10cSrcweir     //         // CPPUNIT_ASSERT_STUB();
103cdf0e10cSrcweir     //     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
106cdf0e10cSrcweir     // member functions of the current class,
107cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(Memory);
110cdf0e10cSrcweir     CPPUNIT_TEST(rtl_allocateMemory_001);
111cdf0e10cSrcweir     CPPUNIT_TEST(rtl_reallocateMemory_001);
112cdf0e10cSrcweir     // CPPUNIT_TEST(rtl_freeMemory_001);
113cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
114cdf0e10cSrcweir }; // class test
115cdf0e10cSrcweir 
116cdf0e10cSrcweir class ZeroMemory : public CppUnit::TestFixture
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     // for zero functions
119cdf0e10cSrcweir     char       *m_pZeroMemory;
120cdf0e10cSrcweir     sal_uInt32  m_nSizeOfZeroMemory;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir public:
ZeroMemory()123cdf0e10cSrcweir     ZeroMemory()
124cdf0e10cSrcweir             :m_pZeroMemory(NULL),
125cdf0e10cSrcweir              m_nSizeOfZeroMemory( 50 * 1024 * 1024 )
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     // initialise your test code values here.
setUp()130cdf0e10cSrcweir     void setUp()
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             t_print("allocate zero memory\n");
133cdf0e10cSrcweir             m_pZeroMemory = (char*) rtl_allocateZeroMemory( m_nSizeOfZeroMemory );
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir 
tearDown()136cdf0e10cSrcweir     void tearDown()
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir             t_print("free zero memory\n");
139cdf0e10cSrcweir             rtl_freeZeroMemory(m_pZeroMemory, m_nSizeOfZeroMemory);
140cdf0e10cSrcweir             // LLA: no check possible, may GPF if there is something wrong.
141cdf0e10cSrcweir             // CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", pZeroMemory != NULL);
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     // insert your test code here.
145cdf0e10cSrcweir 
rtl_allocateZeroMemory_001()146cdf0e10cSrcweir     void rtl_allocateZeroMemory_001()
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory != NULL);
149cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 0) == true);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             memset(m_pZeroMemory, 3, m_nSizeOfZeroMemory);
152cdf0e10cSrcweir             CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory, m_nSizeOfZeroMemory, 3) == true);
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
156cdf0e10cSrcweir     // member functions of the current class,
157cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(ZeroMemory);
160cdf0e10cSrcweir     CPPUNIT_TEST(rtl_allocateZeroMemory_001);
161cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
162cdf0e10cSrcweir }; // class test
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // -----------------------------------------------------------------------------
165cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::Memory, "rtl_alloc");
166cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_alloc::ZeroMemory, "rtl_alloc");
167cdf0e10cSrcweir } // namespace rtl_alloc
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir // -----------------------------------------------------------------------------
171cdf0e10cSrcweir 
172cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
173cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
174cdf0e10cSrcweir NOADDITIONAL;
175cdf0e10cSrcweir 
176