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
41namespace Nektar
42{
43namespace MemManagerUnitTests
44{
45BOOST_AUTO_TEST_CASE(testParameterizedConstructors)
46{
48
54
55 unsigned int one = 1;
61
62 unsigned int two = 2;
64 MemoryManager<CountedObject<int>>::Allocate(one, two);
69
70 unsigned int three = 3;
72 MemoryManager<CountedObject<int>>::Allocate(one, two, three);
77 BOOST_CHECK_EQUAL(ob4->value, 6u);
78
79 MemoryManager<CountedObject<int>>::Deallocate(ob1);
80 MemoryManager<CountedObject<int>>::Deallocate(ob2);
81 MemoryManager<CountedObject<int>>::Deallocate(ob3);
82 MemoryManager<CountedObject<int>>::Deallocate(ob4);
83
84 BOOST_CHECK(ob1 == NULL);
85 BOOST_CHECK(ob2 == NULL);
86 BOOST_CHECK(ob3 == NULL);
87 BOOST_CHECK(ob4 == NULL);
88
93 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
94}
95
96BOOST_AUTO_TEST_CASE(testSmartPointerAllocation)
97{
99
100 {
101 std::shared_ptr<CountedObject<int>> ob1 =
102 MemoryManager<CountedObject<int>>::AllocateSharedPtr();
105 0u);
107 0u);
109 0u);
110
111 int one = 1;
112 std::shared_ptr<CountedObject<int>> ob2 =
113 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one);
116 1u);
118 0u);
120 0u);
121
122 int two = 2;
123 std::shared_ptr<CountedObject<int>> ob3 =
124 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one, two);
127 1u);
129 1u);
131 0u);
132
133 int three = 3;
134 std::shared_ptr<CountedObject<int>> ob4 =
135 MemoryManager<CountedObject<int>>::AllocateSharedPtr(one, two,
136 three);
139 1u);
141 1u);
143 1u);
144 BOOST_CHECK_EQUAL(ob4->value, 6u);
145 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 0u);
146 }
147
148 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
153 BOOST_CHECK_EQUAL(CountedObject<int>::numberDestroyed, 4u);
154}
155
156BOOST_AUTO_TEST_CASE(ReproduceMemoryErrors)
157{
158 std::shared_ptr<int> m = MemoryManager<int>::AllocateSharedPtr();
159 std::shared_ptr<int> m1 = MemoryManager<int>::AllocateSharedPtr();
161}
162} // namespace MemManagerUnitTests
163} // namespace Nektar
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)
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2