1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 // small memory check routine, which return false, if there is a problem
33 bool checkMemory(char* _pMemory
, sal_uInt32 _nSize
, char _n
)
37 for (sal_uInt32 i
=0;i
<_nSize
;i
++)
39 if (_pMemory
[i
] != _n
)
47 class Memory
: public CppUnit::TestFixture
49 // for normal alloc functions
51 sal_uInt32 m_nSizeOfMemory
;
56 , m_nSizeOfMemory(1024)
60 // initialise your test code values here.
61 void setUp() SAL_OVERRIDE
63 m_pMemory
= static_cast<char*>(rtl_allocateMemory( m_nSizeOfMemory
));
66 void tearDown() SAL_OVERRIDE
68 rtl_freeMemory(m_pMemory
);
72 void rtl_allocateMemory_001()
74 CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pMemory
!= NULL
);
75 memset(m_pMemory
, 1, m_nSizeOfMemory
);
76 CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory
, m_nSizeOfMemory
, 1));
79 void rtl_reallocateMemory_001()
81 sal_uInt32 nSize
= 2 * 1024;
82 m_pMemory
= static_cast<char*>(rtl_reallocateMemory(m_pMemory
, nSize
));
84 CPPUNIT_ASSERT_MESSAGE( "Can reallocate memory.", m_pMemory
!= NULL
);
85 memset(m_pMemory
, 2, nSize
);
86 CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pMemory
, nSize
, 2));
89 CPPUNIT_TEST_SUITE(Memory
);
90 CPPUNIT_TEST(rtl_allocateMemory_001
);
91 CPPUNIT_TEST(rtl_reallocateMemory_001
);
92 CPPUNIT_TEST_SUITE_END();
95 class TestZeroMemory
: public CppUnit::TestFixture
99 sal_uInt32 m_nSizeOfZeroMemory
;
103 : m_pZeroMemory(NULL
)
104 , m_nSizeOfZeroMemory( 50 * 1024 * 1024 )
108 // initialise your test code values here.
109 void setUp() SAL_OVERRIDE
111 m_pZeroMemory
= static_cast<char*>(rtl_allocateZeroMemory( m_nSizeOfZeroMemory
));
114 void tearDown() SAL_OVERRIDE
116 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);
121 // insert your test code here.
123 void rtl_allocateZeroMemory_001()
125 CPPUNIT_ASSERT_MESSAGE( "Can get zero memory.", m_pZeroMemory
!= NULL
);
126 CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory
, m_nSizeOfZeroMemory
, 0));
128 memset(m_pZeroMemory
, 3, m_nSizeOfZeroMemory
);
129 CPPUNIT_ASSERT_MESSAGE( "memory contains wrong value.", checkMemory(m_pZeroMemory
, m_nSizeOfZeroMemory
, 3));
132 CPPUNIT_TEST_SUITE(TestZeroMemory
);
133 CPPUNIT_TEST(rtl_allocateZeroMemory_001
);
134 CPPUNIT_TEST_SUITE_END();
137 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::Memory
);
138 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_alloc::TestZeroMemory
);
139 } // namespace rtl_alloc
141 CPPUNIT_PLUGIN_IMPLEMENT();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */