2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
21 // Internal headers are allowed here
23 #include <dali/internal/common/memory-pool-object-allocator.h>
27 void utc_dali_internal_memorypoolobjectallocator_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_internal_memorypoolobjectallocator_cleanup(void)
34 test_return_value = TET_PASS;
37 struct MemoryPoolObjectAllocatorTestObjectTracking
39 int testObjectDestructed;
41 int testObjectDataAccess;
43 MemoryPoolObjectAllocatorTestObjectTracking()
44 : testObjectDestructed(0),
46 testObjectDataAccess(0)
51 class MemoryPoolObjectAllocatorTestObject
54 MemoryPoolObjectAllocatorTestObject()
61 ~MemoryPoolObjectAllocatorTestObject()
65 mTracking->testObjectDestructed++;
73 mTracking->testObjectMethod++;
84 mTracking->testObjectDataAccess++;
88 void SetTracking(MemoryPoolObjectAllocatorTestObjectTracking* tracking)
97 MemoryPoolObjectAllocatorTestObjectTracking* mTracking;
100 int UtcDaliMemoryPoolObjectAllocatorObjectAllocation(void)
102 Internal::MemoryPoolObjectAllocator<MemoryPoolObjectAllocatorTestObject> allocator;
104 // Allocate an object
105 MemoryPoolObjectAllocatorTestObject* testObject1 = allocator.Allocate();
106 DALI_TEST_CHECK(testObject1);
108 MemoryPoolObjectAllocatorTestObjectTracking tracking1;
109 testObject1->SetTracking(&tracking1);
111 testObject1->Method();
112 DALI_TEST_EQUALS(tracking1.testObjectMethod, 1, TEST_LOCATION);
114 testObject1->DataAccess();
115 DALI_TEST_EQUALS(tracking1.testObjectDataAccess, 1, TEST_LOCATION);
117 allocator.Destroy(testObject1);
118 DALI_TEST_EQUALS(tracking1.testObjectDestructed, 1, TEST_LOCATION);
120 // Reset and allocate another object
121 allocator.ResetMemoryPool();
123 MemoryPoolObjectAllocatorTestObject* testObject2 = allocator.Allocate();
124 DALI_TEST_CHECK(testObject2);
126 MemoryPoolObjectAllocatorTestObjectTracking tracking2;
127 testObject2->SetTracking(&tracking2);
129 testObject2->Method();
130 DALI_TEST_EQUALS(tracking2.testObjectMethod, 1, TEST_LOCATION);
132 testObject2->DataAccess();
133 DALI_TEST_EQUALS(tracking2.testObjectDataAccess, 1, TEST_LOCATION);
135 allocator.Destroy(testObject2);
136 DALI_TEST_EQUALS(tracking2.testObjectDestructed, 1, TEST_LOCATION);
141 int UtcDaliMemoryPoolObjectAllocatorObjectRawAllocation(void)
143 Internal::MemoryPoolObjectAllocator<MemoryPoolObjectAllocatorTestObject> allocator;
145 MemoryPoolObjectAllocatorTestObject* testObject = new(allocator.AllocateRaw()) MemoryPoolObjectAllocatorTestObject();
146 DALI_TEST_CHECK(testObject);
148 MemoryPoolObjectAllocatorTestObjectTracking tracking;
149 testObject->SetTracking(&tracking);
151 testObject->Method();
152 DALI_TEST_EQUALS(tracking.testObjectMethod, 1, TEST_LOCATION);
154 testObject->DataAccess();
155 DALI_TEST_EQUALS(tracking.testObjectDataAccess, 1, TEST_LOCATION);
157 allocator.Destroy(testObject);
158 DALI_TEST_EQUALS(tracking.testObjectDestructed, 1, TEST_LOCATION);
163 int UtcDaliMemoryPoolObjectAllocatorObjectAllocationPOD(void)
165 Internal::MemoryPoolObjectAllocator<bool> allocator;
167 bool* testObject1 = allocator.Allocate();
168 DALI_TEST_CHECK(testObject1);
170 allocator.Destroy(testObject1);
172 allocator.ResetMemoryPool();
174 bool* testObject2 = allocator.Allocate();
175 DALI_TEST_CHECK(testObject2);
177 allocator.Destroy(testObject2);