Dali 3D User Interface Engine
utc-Dali-Internal-MemoryPoolObjectAllocator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
19 #include <dali-test-suite-utils.h>
20 
21 // Internal headers are allowed here
22 
24 
25 using namespace Dali;
26 
28 {
30 }
31 
33 {
35 }
36 
38 {
42 
44  : testObjectDestructed( 0 ),
45  testObjectMethod( 0 ),
46  testObjectDataAccess( 0 )
47  {
48  }
49 };
50 
52 {
53 public:
54 
56  : mData1( 0 ),
57  mData2( false ),
58  mTracking( NULL )
59  {
60  }
61 
63  {
64  if( mTracking )
65  {
66  mTracking->testObjectDestructed++;
67  }
68  }
69 
70  void Method()
71  {
72  if( mTracking )
73  {
74  mTracking->testObjectMethod++;
75  }
76  }
77 
78  void DataAccess()
79  {
80  mData1++;
81  mData2 = true;
82 
83  if( mTracking )
84  {
85  mTracking->testObjectDataAccess++;
86  }
87  }
88 
89  void SetTracking( MemoryPoolObjectAllocatorTestObjectTracking* tracking )
90  {
91  mTracking = tracking;
92  }
93 
94 private:
95 
96  int mData1;
97  bool mData2;
98 
100 };
101 
103 {
104 
105  Internal::MemoryPoolObjectAllocator< MemoryPoolObjectAllocatorTestObject > allocator;
106 
107  // Allocate an object
108  MemoryPoolObjectAllocatorTestObject* testObject1 = allocator.Allocate();
109  DALI_TEST_CHECK( testObject1 );
110 
112  testObject1->SetTracking( &tracking1 );
113 
114  testObject1->Method();
116 
117  testObject1->DataAccess();
119 
120  allocator.Free( testObject1 );
122 
123  // Reset and allocate another object
124  allocator.ResetMemoryPool();
125 
126  MemoryPoolObjectAllocatorTestObject* testObject2 = allocator.Allocate();
127  DALI_TEST_CHECK( testObject2 );
128 
130  testObject2->SetTracking( &tracking2 );
131 
132  testObject2->Method();
134 
135  testObject2->DataAccess();
137 
138  allocator.Free( testObject2 );
140 
141  END_TEST;
142 }
143 
145 {
146  Internal::MemoryPoolObjectAllocator< MemoryPoolObjectAllocatorTestObject > allocator;
147 
148  MemoryPoolObjectAllocatorTestObject* testObject = new ( allocator.AllocateRaw() ) MemoryPoolObjectAllocatorTestObject();
149  DALI_TEST_CHECK( testObject );
150 
152  testObject->SetTracking( &tracking );
153 
154  testObject->Method();
156 
157  testObject->DataAccess();
159 
160  allocator.Free( testObject );
162 
163  END_TEST;
164 }
165 
167 {
168  Internal::MemoryPoolObjectAllocator< bool > allocator;
169 
170  bool* testObject1 = allocator.Allocate();
171  DALI_TEST_CHECK( testObject1 );
172 
173  allocator.Free( testObject1 );
174 
175  allocator.ResetMemoryPool();
176 
177  bool* testObject2 = allocator.Allocate();
178  DALI_TEST_CHECK( testObject2 );
179 
180  allocator.Free( testObject2 );
181 
182  END_TEST;
183 }
Dali Docs Home
Read more about Dali