2 * Copyright (c) 2015 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/public-api/dali-core.h>
19 #include <dali-test-suite-utils.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 ),
45 testObjectMethod( 0 ),
46 testObjectDataAccess( 0 )
51 class MemoryPoolObjectAllocatorTestObject
55 MemoryPoolObjectAllocatorTestObject()
62 ~MemoryPoolObjectAllocatorTestObject()
66 mTracking->testObjectDestructed++;
74 mTracking->testObjectMethod++;
85 mTracking->testObjectDataAccess++;
89 void SetTracking( MemoryPoolObjectAllocatorTestObjectTracking* tracking )
99 MemoryPoolObjectAllocatorTestObjectTracking* mTracking;
102 int UtcDaliMemoryPoolObjectAllocatorObjectAllocation(void)
105 Internal::MemoryPoolObjectAllocator< MemoryPoolObjectAllocatorTestObject > allocator;
107 // Allocate an object
108 MemoryPoolObjectAllocatorTestObject* testObject1 = allocator.Allocate();
109 DALI_TEST_CHECK( testObject1 );
111 MemoryPoolObjectAllocatorTestObjectTracking tracking1;
112 testObject1->SetTracking( &tracking1 );
114 testObject1->Method();
115 DALI_TEST_EQUALS( tracking1.testObjectMethod, 1, TEST_LOCATION );
117 testObject1->DataAccess();
118 DALI_TEST_EQUALS( tracking1.testObjectDataAccess, 1, TEST_LOCATION );
120 allocator.Free( testObject1 );
121 DALI_TEST_EQUALS( tracking1.testObjectDestructed, 1, TEST_LOCATION );
123 // Reset and allocate another object
124 allocator.ResetMemoryPool();
126 MemoryPoolObjectAllocatorTestObject* testObject2 = allocator.Allocate();
127 DALI_TEST_CHECK( testObject2 );
129 MemoryPoolObjectAllocatorTestObjectTracking tracking2;
130 testObject2->SetTracking( &tracking2 );
132 testObject2->Method();
133 DALI_TEST_EQUALS( tracking2.testObjectMethod, 1, TEST_LOCATION );
135 testObject2->DataAccess();
136 DALI_TEST_EQUALS( tracking2.testObjectDataAccess, 1, TEST_LOCATION );
138 allocator.Free( testObject2 );
139 DALI_TEST_EQUALS( tracking2.testObjectDestructed, 1, TEST_LOCATION );
144 int UtcDaliMemoryPoolObjectAllocatorObjectRawAllocation(void)
146 Internal::MemoryPoolObjectAllocator< MemoryPoolObjectAllocatorTestObject > allocator;
148 MemoryPoolObjectAllocatorTestObject* testObject = new ( allocator.AllocateRaw() ) MemoryPoolObjectAllocatorTestObject();
149 DALI_TEST_CHECK( testObject );
151 MemoryPoolObjectAllocatorTestObjectTracking tracking;
152 testObject->SetTracking( &tracking );
154 testObject->Method();
155 DALI_TEST_EQUALS( tracking.testObjectMethod, 1, TEST_LOCATION );
157 testObject->DataAccess();
158 DALI_TEST_EQUALS( tracking.testObjectDataAccess, 1, TEST_LOCATION );
160 allocator.Free( testObject );
161 DALI_TEST_EQUALS( tracking.testObjectDestructed, 1, TEST_LOCATION );
166 int UtcDaliMemoryPoolObjectAllocatorObjectAllocationPOD(void)
168 Internal::MemoryPoolObjectAllocator< bool > allocator;
170 bool* testObject1 = allocator.Allocate();
171 DALI_TEST_CHECK( testObject1 );
173 allocator.Free( testObject1 );
175 allocator.ResetMemoryPool();
177 bool* testObject2 = allocator.Allocate();
178 DALI_TEST_CHECK( testObject2 );
180 allocator.Free( testObject2 );