Remove RenderSurface from Core
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-FixedSizeMemoryPool.cpp
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
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 // Internal headers are allowed here
22
23 #include <dali/internal/common/fixed-size-memory-pool.h>
24
25 using namespace Dali;
26
27 void utc_dali_internal_fixedsizememorypool_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_internal_fixedsizememorypool_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 unsigned int gTestObjectConstructed = 0;
41 unsigned int gTestObjectDestructed = 0;
42 unsigned int gTestObjectMethod = 0;
43 unsigned int gTestObjectDataAccess = 0;
44
45 } // namespace
46
47
48 class TestObject
49 {
50 public:
51
52   TestObject()
53   : mData1( 0 ),
54     mData2( false )
55   {
56     gTestObjectConstructed++;
57   }
58
59   ~TestObject()
60   {
61     gTestObjectDestructed++;
62   }
63
64   void Method()
65   {
66     gTestObjectMethod++;
67   }
68
69   void DataAccess()
70   {
71     mData1++;
72     mData2 = true;
73
74     gTestObjectDataAccess++;
75   }
76
77 private:
78
79   unsigned int mData1;
80   bool mData2;
81
82 };
83
84 int UtcDaliFixedSizeMemoryPoolCreate(void)
85 {
86   gTestObjectConstructed = 0;
87   gTestObjectDestructed = 0;
88   gTestObjectMethod = 0;
89   gTestObjectDataAccess = 0;
90
91   Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size );
92
93   TestObject* testObject1 = new (memoryPool.Allocate()) TestObject();
94   DALI_TEST_CHECK( testObject1 );
95   DALI_TEST_EQUALS( gTestObjectConstructed, 1U, TEST_LOCATION );
96
97   testObject1->Method();
98   DALI_TEST_EQUALS( gTestObjectMethod, 1U, TEST_LOCATION );
99
100   testObject1->DataAccess();
101   DALI_TEST_EQUALS( gTestObjectDataAccess, 1U, TEST_LOCATION );
102
103   testObject1->~TestObject();
104   memoryPool.Free( testObject1 );
105   DALI_TEST_EQUALS( gTestObjectDestructed, 1U, TEST_LOCATION );
106
107   END_TEST;
108 }
109
110 int UtcDaliFixedSizeMemoryPoolStressTest(void)
111 {
112   gTestObjectConstructed = 0;
113   gTestObjectDestructed = 0;
114   gTestObjectMethod = 0;
115   gTestObjectDataAccess = 0;
116
117   const size_t initialCapacity = 32;
118   const size_t maximumCapacity = 1024;
119
120   const unsigned int numObjects = 1024 * 1024;
121
122   Internal::FixedSizeMemoryPool memoryPool( Internal::TypeSizeWithAlignment< TestObject >::size, initialCapacity, maximumCapacity );
123
124   Dali::Vector<TestObject*> objects;
125   objects.Reserve( numObjects );
126
127   for( unsigned int i = 0; i < numObjects; ++i )
128   {
129     TestObject* testObject = new ( memoryPool.Allocate() ) TestObject();
130     DALI_TEST_CHECK( testObject );
131
132     objects.PushBack( testObject );
133   }
134
135   DALI_TEST_EQUALS( gTestObjectConstructed, numObjects, TEST_LOCATION );
136
137   for( unsigned int i = 0; i < numObjects; ++i )
138   {
139     objects[i]->~TestObject();
140     memoryPool.Free( objects[i] );
141   }
142
143   DALI_TEST_EQUALS( gTestObjectDestructed, numObjects, TEST_LOCATION );
144
145   END_TEST;
146 }