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>
23 void utc_dali_fixedsizememorypool_startup(void)
25 test_return_value = TET_UNDEF;
28 void utc_dali_fixedsizememorypool_cleanup(void)
30 test_return_value = TET_PASS;
36 int gTestObjectConstructed = 0;
37 int gTestObjectDestructed = 0;
38 int gTestObjectMethod = 0;
39 int gTestObjectDataAccess = 0;
52 gTestObjectConstructed++;
57 gTestObjectDestructed++;
70 gTestObjectDataAccess++;
80 int UtcDaliFixedSizeMemoryPoolCreate(void)
82 gTestObjectConstructed = 0;
83 gTestObjectDestructed = 0;
84 gTestObjectMethod = 0;
85 gTestObjectDataAccess = 0;
87 FixedSizeMemoryPool memoryPool( TypeSizeWithAlignment< TestObject >::size );
89 TestObject* testObject1 = new (memoryPool.Allocate()) TestObject();
90 DALI_TEST_CHECK( testObject1 );
91 DALI_TEST_EQUALS( gTestObjectConstructed, 1, TEST_LOCATION );
93 testObject1->Method();
94 DALI_TEST_EQUALS( gTestObjectMethod, 1, TEST_LOCATION );
96 testObject1->DataAccess();
97 DALI_TEST_EQUALS( gTestObjectDataAccess, 1, TEST_LOCATION );
99 testObject1->~TestObject();
100 memoryPool.Free( testObject1 );
101 DALI_TEST_EQUALS( gTestObjectDestructed, 1, TEST_LOCATION );
106 int UtcDaliFixedSizeMemoryPoolStressTest(void)
108 gTestObjectConstructed = 0;
109 gTestObjectDestructed = 0;
110 gTestObjectMethod = 0;
111 gTestObjectDataAccess = 0;
113 const size_t initialCapacity = 32;
114 const size_t maximumCapacity = 1024;
116 const unsigned int numObjects = 1024 * 1024;
118 FixedSizeMemoryPool memoryPool( TypeSizeWithAlignment< TestObject >::size, initialCapacity, maximumCapacity );
120 Dali::Vector<TestObject*> objects;
121 objects.Reserve( numObjects );
123 for( unsigned int i = 0; i < numObjects; ++i )
125 TestObject* testObject = new ( memoryPool.Allocate() ) TestObject();
126 DALI_TEST_CHECK( testObject );
128 objects.PushBack( testObject );
131 DALI_TEST_EQUALS( gTestObjectConstructed, numObjects, TEST_LOCATION );
133 for( unsigned int i = 0; i < numObjects; ++i )
135 objects[i]->~TestObject();
136 memoryPool.Free( objects[i] );
139 DALI_TEST_EQUALS( gTestObjectDestructed, numObjects, TEST_LOCATION );