Nektar++
TestNekMemoryManager.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestNekMemoryManager.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Tests the boost utility functions.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#define NEKTAR_MAX_MEMORY_MANAGER_CONSTRUCTOR_ARGS 4
36
38
40
42{
43BOOST_AUTO_TEST_CASE(testParameterizedConstructors)
44{
46
52
53 unsigned int one = 1;
59
60 unsigned int two = 2;
62 MemoryManager<CountedObject<int>>::Allocate(one, two);
67
68 unsigned int three = 3;
70 MemoryManager<CountedObject<int>>::Allocate(one, two, three);
75 BOOST_CHECK_EQUAL(ob4->value, 6u);
76
77 MemoryManager<CountedObject<int>>::Deallocate(ob1);
78 MemoryManager<CountedObject<int>>::Deallocate(ob2);
79 MemoryManager<CountedObject<int>>::Deallocate(ob3);
80 MemoryManager<CountedObject<int>>::Deallocate(ob4);
81
82 BOOST_CHECK(ob1 == nullptr);
83 BOOST_CHECK(ob2 == nullptr);
84 BOOST_CHECK(ob3 == nullptr);
85 BOOST_CHECK(ob4 == nullptr);
86
91 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
92}
93
94BOOST_AUTO_TEST_CASE(testSmartPointerAllocation)
95{
97
98 {
99 std::shared_ptr<CountedObject<int>> ob1 =
100 MemoryManager<CountedObject<int>>::AllocateSharedPtr();
103 0u);
105 0u);
107 0u);
108
109 int one = 1;
110 std::shared_ptr<CountedObject<int>> ob2 =
111 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one);
114 1u);
116 0u);
118 0u);
119
120 int two = 2;
121 std::shared_ptr<CountedObject<int>> ob3 =
122 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one, two);
125 1u);
127 1u);
129 0u);
130
131 int three = 3;
132 std::shared_ptr<CountedObject<int>> ob4 =
133 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one, two,
134 three);
137 1u);
139 1u);
141 1u);
142 BOOST_CHECK_EQUAL(ob4->value, 6u);
143 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 0u);
144 }
145
146 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
151 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
152}
153
154BOOST_AUTO_TEST_CASE(ReproduceMemoryErrors)
155{
156 std::shared_ptr<int> m = MemoryManager<int>::AllocateSharedPtr();
157 std::shared_ptr<int> m1 = MemoryManager<int>::AllocateSharedPtr();
159}
160} // namespace Nektar::MemManagerUnitTests
static void ClearCounters()
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
BOOST_AUTO_TEST_CASE(testParameterizedConstructors)