2 * Copyright (c) 2021 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 "test-gesture-generator.h"
21 #include <dali/integration-api/events/touch-event-integ.h>
25 const uint32_t RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS)
27 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition, uint32_t time)
29 Integration::TouchEvent touchEvent;
30 Integration::Point point;
31 point.SetState(state);
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;
41 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
43 Integration::TouchEvent touchEvent;
44 Integration::Point point;
45 point.SetState(stateA);
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);
54 touchEvent.points.push_back(point);
55 touchEvent.time = time;
62 uint32_t TestGetFrameInterval()
64 return RENDER_FRAME_INTERVAL;
67 void TestStartLongPress(TestApplication& application, float x, float y, uint32_t time)
69 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(x, y), time));
72 void TestTriggerLongPress(TestApplication& application)
74 application.GetPlatform().TriggerTimer();
77 void TestGenerateLongPress(TestApplication& application, float x, float y, uint32_t time)
79 TestStartLongPress(application, x, y, time);
80 TestTriggerLongPress(application);
83 void TestEndLongPress(TestApplication& application, float x, float y, uint32_t time)
85 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(x, y), time));
88 void TestGeneratePinch(TestApplication& application)
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));
98 void TestStartPinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
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));
106 void TestContinuePinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
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));
114 void TestEndPinch(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
116 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
117 application.ProcessEvent(GenerateDoubleTouch(PointState::UP, a2, PointState::UP, b2, time + 50));
120 void TestGenerateMiniPan(TestApplication& application)
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));
127 void TestStartPan(TestApplication& application, Vector2 start, Vector2 end, uint32_t& time)
129 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, start, time));
131 time += RENDER_FRAME_INTERVAL;
133 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, end, time));
135 time += RENDER_FRAME_INTERVAL;
137 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, end, time));
139 time += RENDER_FRAME_INTERVAL;
142 void TestMovePan(TestApplication& application, Vector2 pos, uint32_t time)
144 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, pos, time));
147 void TestEndPan(TestApplication& application, Vector2 pos, uint32_t time)
149 application.ProcessEvent(GenerateSingleTouch(PointState::UP, pos, time));
152 void TestTriggerTap(TestApplication& application)
154 application.GetPlatform().TriggerTimer();
157 void TestGenerateTap(TestApplication& application, float x, float y, uint32_t time_down)
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);
164 void TestGenerateTwoPointTap(TestApplication& application, float x1, float y1, float x2, float y2, uint32_t time_down)
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);
171 void TestGenerateRotation(TestApplication& application)
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));
181 void TestStartRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
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));
189 void TestContinueRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
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));
197 void TestEndRotation(TestApplication& application, Vector2 a1, Vector2 b1, Vector2 a2, Vector2 b2, uint32_t time)
199 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, a1, PointState::MOTION, b1, time));
200 application.ProcessEvent(GenerateDoubleTouch(PointState::UP, a2, PointState::UP, b2, time + 50));