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/fixed-size-memory-pool.h>
27 void utc_dali_internal_fixedsizememorypool_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_internal_fixedsizememorypool_cleanup(void)
34 test_return_value = TET_PASS;
40 unsigned int gTestObjectConstructed = 0;
41 unsigned int gTestObjectDestructed = 0;
42 unsigned int gTestObjectMethod = 0;
43 unsigned int gTestObjectDataAccess = 0;
56 gTestObjectConstructed++;
61 gTestObjectDestructed++;
74 gTestObjectDataAccess++;
84 int UtcDaliFixedSizeMemoryPoolCreate(void)
86 gTestObjectConstructed = 0;
87 gTestObjectDestructed = 0;
88 gTestObjectMethod = 0;
89 gTestObjectDataAccess = 0;
91 Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size );
93 TestObject* testObject1 = new (memoryPool.Allocate()) TestObject();
94 DALI_TEST_CHECK( testObject1 );
95 DALI_TEST_EQUALS( gTestObjectConstructed, 1U, TEST_LOCATION );
97 testObject1->Method();
98 DALI_TEST_EQUALS( gTestObjectMethod, 1U, TEST_LOCATION );
100 testObject1->DataAccess();
101 DALI_TEST_EQUALS( gTestObjectDataAccess, 1U, TEST_LOCATION );
103 testObject1->~TestObject();
104 memoryPool.Free( testObject1 );
105 DALI_TEST_EQUALS( gTestObjectDestructed, 1U, TEST_LOCATION );
110 int UtcDaliFixedSizeMemoryPoolStressTest(void)
112 gTestObjectConstructed = 0;
113 gTestObjectDestructed = 0;
114 gTestObjectMethod = 0;
115 gTestObjectDataAccess = 0;
117 const size_t initialCapacity = 32;
118 const size_t maximumCapacity = 1024;
120 const unsigned int numObjects = 1024 * 1024;
122 Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size, initialCapacity, maximumCapacity );
124 Dali::Vector<TestObject*> objects;
125 objects.Reserve( numObjects );
127 for( unsigned int i = 0; i < numObjects; ++i )
129 TestObject* testObject = new ( memoryPool.Allocate() ) TestObject();
130 DALI_TEST_CHECK( testObject );
132 objects.PushBack( testObject );
135 DALI_TEST_EQUALS( gTestObjectConstructed, numObjects, TEST_LOCATION );
137 for( unsigned int i = 0; i < numObjects; ++i )
139 objects[i]->~TestObject();
140 memoryPool.Free( objects[i] );
143 DALI_TEST_EQUALS( gTestObjectDestructed, numObjects, TEST_LOCATION );