[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gesture-generator.cpp
1 /*
2  * Copyright (c) 2021 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 "test-gesture-generator.h"
19
20 // INTERNAL INCLUDES
21 #include <dali/integration-api/events/touch-event-integ.h>
22
23 namespace
24 {
25 const uint32_t RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
26
27 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
28 {
29   Integration::TouchEvent touchEvent;
30   Integration::Point      point;
31   point.SetState(state);
32   point.SetDeviceId(4);
33   point.SetScreenPosition(screenPosition);
34   point.SetDeviceClass(Device::Class::TOUCH);
35   point.SetDeviceSubclass(Device::Subclass::NONE);
36   touchEvent.points.push_back(point);
37   touchEvent.time = time;
38   return touchEvent;
39 }
40
41 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
42 {
43   Integration::TouchEvent touchEvent;
44   Integration::Point      point;
45   point.SetState(stateA);
46   point.SetDeviceId(4);
47   point.SetScreenPosition(screenPositionA);
48   point.SetDeviceClass(Device::Class::TOUCH);
49   point.SetDeviceSubclass(Device::Subclass::NONE);
50   touchEvent.points.push_back(point);
51   point.SetScreenPosition(screenPositionB);
52   point.SetState(stateB);
53   point.SetDeviceId(7);
54   touchEvent.points.push_back(point);
55   touchEvent.time = time;
56   return touchEvent;
57 }
58 } // namespace
59
60 namespace Dali
61 {
62 uint32_t TestGetFrameInterval()
63 {
64   return RENDER_FRAME_INTERVAL;
65 }
66
67 void TestStartLongPress(TestApplication& application, float x, float y, uint32_t time)
68 {
69   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(x, y), time));
70 }
71
72 void TestTriggerLongPress(TestApplication& application)
73 {
74   application.GetPlatform().TriggerTimer();
75 }
76
77 void TestGenerateLongPress(TestApplication& application, float x, float y, uint32_t time)
78 {
79   TestStartLongPress(application, x, y, time);
80   TestTriggerLongPress(application);
81 }
82
83 void TestEndLongPress(TestApplication& application, float x, float y, uint32_t time)
84 {
85   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(x, y), time));
86 }
87
88 void TestGeneratePinch(TestApplication& application)
89 {
90   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
91   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 28.0f), PointState::MOTION, Vector2(20.0f, 82.0f), 160));
92   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 37.0f), PointState::MOTION, Vector2(20.0f, 74.0f), 170));
93   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 46.0f), PointState::MOTION, Vector2(20.0f, 66.0f), 180));
94   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 55.0f), PointState::MOTION, Vector2(20.0f, 58.0f), 190));
95   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(20.0f, 55.0f), PointState::UP, Vector2(20.0f, 58.0f), 200));
96 }
97
98 void TestStartPinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
99 {
100   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, a1, PointState::DOWN, b1, time));
101   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 50));
102   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 100));
103   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 150));
104 }
105
106 void TestContinuePinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
107 {
108   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
109   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time + 50));
110   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 100));
111   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 150));
112 }
113
114 void TestEndPinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
115 {
116   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
117   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, a2, PointState::UP, b2, time + 50));
118 }
119
120 void TestGenerateMiniPan(TestApplication& application)
121 {
122   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 250));
123   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 40.0f), 251));
124   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 40.0f), 255));
125 }
126
127 void TestStartPan(TestApplication& application, Vector2 start, Vector2 end, uint32_t& time)
128 {
129   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, start, time));
130
131   time += RENDER_FRAME_INTERVAL;
132
133   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, end, time));
134
135   time += RENDER_FRAME_INTERVAL;
136
137   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, end, time));
138
139   time += RENDER_FRAME_INTERVAL;
140 }
141
142 void TestMovePan(TestApplication& application, Vector2 pos, uint32_t time)
143 {
144   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, pos, time));
145 }
146
147 void TestEndPan(TestApplication& application, Vector2 pos, uint32_t time)
148 {
149   application.ProcessEvent(GenerateSingleTouch(PointState::UP, pos, time));
150 }
151
152 void TestTriggerTap(TestApplication& application)
153 {
154   application.GetPlatform().TriggerTimer();
155 }
156
157 void TestGenerateTap(TestApplication& application, float x, float y, uint32_t time_down)
158 {
159   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(x, y), time_down));
160   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(x, y), time_down + 20));
161   TestTriggerTap(application);
162 }
163
164 void TestGenerateTwoPointTap(TestApplication& application, float x1, float y1, float x2, float y2, uint32_t time_down)
165 {
166   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(x1, y1), PointState::DOWN, Vector2(x2, y2), time_down));
167   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(x1, y1), PointState::UP, Vector2(x2, y2), time_down + 20));
168   TestTriggerTap(application);
169 }
170
171 void TestGenerateRotation(TestApplication& application)
172 {
173   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), PointState::DOWN, Vector2(20.0f, 90.0f), 150));
174   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(25.0f, 95.0f), 160));
175   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 100.0f), 170));
176   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(35.0f, 105.0f), 180));
177   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(20.0f, 20.0f), PointState::MOTION, Vector2(40.0f, 110.0f), 190));
178   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, Vector2(20.0f, 20.0f), PointState::UP, Vector2(45.0f, 115.0f), 200));
179 }
180
181 void TestStartRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
182 {
183   application.ProcessEvent(GenerateDoubleTouch(PointState::DOWN, a1, PointState::DOWN, b1, time));
184   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 50));
185   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 100));
186   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 150));
187 }
188
189 void TestContinueRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
190 {
191   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
192   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time + 50));
193   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 100));
194   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a2, PointState::MOTION, b2, time + 150));
195 }
196
197 void TestEndRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
198 {
199   application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
200   application.ProcessEvent(GenerateDoubleTouch(PointState::UP, a2, PointState::UP, b2, time + 50));
201 }
202
203 } // namespace Dali