2 * Copyright (c) 2020 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-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/events/wheel-event-devel.h>
21 #include <dali/integration-api/events/wheel-event-integ.h>
22 #include <dali/public-api/dali-core.h>
31 // Key Event Test references
32 const static unsigned int SHIFT_MODIFIER = 0x1;
33 const static unsigned int CTRL_MODIFIER = 0x2;
34 const static unsigned int ALT_MODIFIER = 0x4;
35 const static unsigned int SHIFT_AND_CTRL_MODIFIER = SHIFT_MODIFIER | CTRL_MODIFIER;
37 // Stores data that is populated in the callback and will be read by the TET cases
41 : functorCalled(false)
47 functorCalled = false;
49 receivedWheelEvent.Reset();
54 WheelEvent receivedWheelEvent;
58 // Functor that sets the data when called
59 struct WheelEventReceivedFunctor
61 WheelEventReceivedFunctor(SignalData& data, bool returnValue = true)
63 returnValue(returnValue)
67 bool operator()(Actor actor, const WheelEvent& wheelEvent)
69 signalData.functorCalled = true;
70 signalData.receivedWheelEvent = wheelEvent;
71 signalData.wheeledActor = actor;
76 SignalData& signalData;
80 } // anonymous namespace
82 int UtcDaliWheelEventConstructor(void)
84 TestApplication application; // Reset all test adapter return codes
86 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
87 DALI_TEST_CHECK(event);
89 DALI_TEST_EQUALS(Dali::WheelEvent::MOUSE_WHEEL, event.GetType(), TEST_LOCATION); // check type
90 DALI_TEST_EQUALS(1, event.GetDirection(), TEST_LOCATION); // check direction
91 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check modifier
92 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.GetPoint(), TEST_LOCATION); // check modifier
93 DALI_TEST_EQUALS(1, event.GetDelta(), TEST_LOCATION); // check modifier
94 DALI_TEST_EQUALS(1000u, event.GetTime(), TEST_LOCATION); // check modifier
98 // Positive test case for a method
99 int UtcDaliWheelEventIsShiftModifier(void)
101 TestApplication application; // Reset all test adapter return codes
103 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
104 DALI_TEST_CHECK(event);
106 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
108 DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
113 // Positive test case for a method
114 int UtcDaliWheelEventIsCtrlModifier(void)
116 TestApplication application; // Reset all test adapter return codes
118 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
119 DALI_TEST_CHECK(event);
121 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION);
123 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
127 // Positive test case for a method
128 int UtcDaliWheelEventIsAltModifier(void)
130 TestApplication application; // Reset all test adapter return codes
132 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
133 DALI_TEST_CHECK(event);
135 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
137 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
141 // Positive fail test case for a method
142 int UtcDaliWheelEventIsNotShiftModifier(void)
144 TestApplication application; // Reset all test adapter return codes
146 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
147 DALI_TEST_CHECK(event);
149 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
151 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
155 // Positive fail test case for a method
156 int UtcDaliWheelEventIsNotCtrlModifier(void)
158 TestApplication application; // Reset all test adapter return codes
160 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
161 DALI_TEST_CHECK(event);
163 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
165 DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
169 // Positive fail test case for a method
170 int UtcDaliWheelEventIsNotAltModifier(void)
172 TestApplication application; // Reset all test adapter return codes
174 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
175 DALI_TEST_CHECK(event);
177 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
179 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
183 // Positive test case for a method
184 int UtcDaliWheelEventANDModifer(void)
186 TestApplication application; // Reset all test adapter return codes
188 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
189 DALI_TEST_CHECK(event);
190 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
192 Dali::WheelEvent newEvent = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
193 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsShiftModifier(), TEST_LOCATION);
197 // Positive test case for a method
198 int UtcDaliWheelEventORModifer(void)
200 TestApplication application; // Reset all test adapter return codes
202 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
203 DALI_TEST_CHECK(event);
204 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
206 Dali::WheelEvent newEvent = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
207 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsAltModifier(), TEST_LOCATION);
211 int UtcDaliWheelEventSignalling(void)
213 TestApplication application; // Reset all test adapter return codes
215 Actor actor = Actor::New();
216 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
217 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
218 application.GetScene().Add(actor);
221 application.SendNotification();
222 application.Render();
224 // Connect to actor's wheel event signal
226 WheelEventReceivedFunctor functor(data);
227 actor.WheelEventSignal().Connect(&application, functor);
229 Vector2 screenCoordinates(10.0f, 10.0f);
230 Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
232 // Emit a wheel signal
233 application.ProcessEvent(event);
234 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
235 DALI_TEST_CHECK(actor == data.wheeledActor);
236 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, data.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
237 DALI_TEST_EQUALS(0, data.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
238 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
239 DALI_TEST_EQUALS(screenCoordinates, data.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
240 DALI_TEST_EQUALS(1, data.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
241 DALI_TEST_EQUALS(1000u, data.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
244 // Emit a wheel signal where the actor is not present, will hit the root actor though
245 Actor rootActor(application.GetScene().GetRootLayer());
247 // Connect to root actor's wheel event signal
249 WheelEventReceivedFunctor rootFunctor(rootData); // Consumes signal
250 rootActor.WheelEventSignal().Connect(&application, rootFunctor);
252 screenCoordinates.x = screenCoordinates.y = 300.0f;
253 Integration::WheelEvent newEvent(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
254 application.ProcessEvent(newEvent);
255 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
256 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
257 DALI_TEST_CHECK(rootActor == rootData.wheeledActor);
258 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, rootData.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
259 DALI_TEST_EQUALS(0, rootData.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
260 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
261 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
262 DALI_TEST_EQUALS(1, rootData.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
263 DALI_TEST_EQUALS(1000u, rootData.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
265 // Remove actor from the scene
266 application.GetScene().Remove(actor);
269 application.SendNotification();
270 application.Render();
272 // Emit a move at the same point, we should not be signalled.
273 application.ProcessEvent(event);
274 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
279 int UtcDaliWheelEventIntercept(void)
281 TestApplication application; // Reset all test adapter return codes
283 Actor actor = Actor::New();
284 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
285 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
286 application.GetScene().Add(actor);
289 application.SendNotification();
290 application.Render();
292 // Connect to actor's wheel event signal
294 WheelEventReceivedFunctor functor(data);
295 actor.WheelEventSignal().Connect(&application, functor);
297 Vector2 screenCoordinates(10.0f, 10.0f);
298 Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
300 // Emit a wheel signal
301 application.ProcessEvent(event);
302 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
303 DALI_TEST_CHECK(actor == data.wheeledActor);
304 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, data.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
305 DALI_TEST_EQUALS(0, data.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
306 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
307 DALI_TEST_EQUALS(screenCoordinates, data.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
308 DALI_TEST_EQUALS(1, data.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
309 DALI_TEST_EQUALS(1000u, data.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
312 // Intercept wheel events on the root actor.
313 Actor rootActor(application.GetScene().GetRootLayer());
315 // Connect to root actor's intercept wheel event signal
317 WheelEventReceivedFunctor rootFunctor(rootData); // Consumes signal
318 Dali::DevelActor::InterceptWheelSignal(rootActor).Connect(&application, rootFunctor);
320 Integration::WheelEvent newEvent(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
321 application.ProcessEvent(newEvent);
323 // It should be able to receive wheel events to root actor by registering only InterceptWheelEvent.
324 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
325 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
326 DALI_TEST_CHECK(rootActor == rootData.wheeledActor);
327 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, rootData.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
328 DALI_TEST_EQUALS(0, rootData.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
329 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
330 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
331 DALI_TEST_EQUALS(1, rootData.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
332 DALI_TEST_EQUALS(1000u, rootData.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
334 // Remove actor from the scene
335 application.GetScene().Remove(actor);
338 application.SendNotification();
339 application.Render();
341 // Emit a move at the same point, we should not be signalled.
342 application.ProcessEvent(event);
343 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);