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