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