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/events/wheel-event-devel.h>
20 #include <dali/integration-api/events/wheel-event-integ.h>
21 #include <dali/public-api/dali-core.h>
30 // Key Event Test references
31 const static unsigned int SHIFT_MODIFIER = 0x1;
32 const static unsigned int CTRL_MODIFIER = 0x2;
33 const static unsigned int ALT_MODIFIER = 0x4;
34 const static unsigned int SHIFT_AND_CTRL_MODIFIER = SHIFT_MODIFIER | CTRL_MODIFIER;
36 // Stores data that is populated in the callback and will be read by the TET cases
40 : functorCalled(false)
46 functorCalled = false;
48 receivedWheelEvent.Reset();
53 WheelEvent receivedWheelEvent;
57 // Functor that sets the data when called
58 struct WheelEventReceivedFunctor
60 WheelEventReceivedFunctor(SignalData& data)
65 bool operator()(Actor actor, const WheelEvent& wheelEvent)
67 signalData.functorCalled = true;
68 signalData.receivedWheelEvent = wheelEvent;
69 signalData.wheeledActor = actor;
74 SignalData& signalData;
77 } // anonymous namespace
79 int UtcDaliWheelEventConstructor(void)
81 TestApplication application; // Reset all test adapter return codes
83 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
84 DALI_TEST_CHECK(event);
86 DALI_TEST_EQUALS(Dali::WheelEvent::MOUSE_WHEEL, event.GetType(), TEST_LOCATION); // check type
87 DALI_TEST_EQUALS(1, event.GetDirection(), TEST_LOCATION); // check direction
88 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check modifier
89 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.GetPoint(), TEST_LOCATION); // check modifier
90 DALI_TEST_EQUALS(1, event.GetDelta(), TEST_LOCATION); // check modifier
91 DALI_TEST_EQUALS(1000u, event.GetTime(), TEST_LOCATION); // check modifier
95 // Positive test case for a method
96 int UtcDaliWheelEventIsShiftModifier(void)
98 TestApplication application; // Reset all test adapter return codes
100 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
101 DALI_TEST_CHECK(event);
103 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
105 DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
110 // Positive test case for a method
111 int UtcDaliWheelEventIsCtrlModifier(void)
113 TestApplication application; // Reset all test adapter return codes
115 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
116 DALI_TEST_CHECK(event);
118 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION);
120 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
124 // Positive test case for a method
125 int UtcDaliWheelEventIsAltModifier(void)
127 TestApplication application; // Reset all test adapter return codes
129 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
130 DALI_TEST_CHECK(event);
132 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
134 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
138 // Positive fail test case for a method
139 int UtcDaliWheelEventIsNotShiftModifier(void)
141 TestApplication application; // Reset all test adapter return codes
143 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
144 DALI_TEST_CHECK(event);
146 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
148 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
152 // Positive fail test case for a method
153 int UtcDaliWheelEventIsNotCtrlModifier(void)
155 TestApplication application; // Reset all test adapter return codes
157 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
158 DALI_TEST_CHECK(event);
160 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
162 DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
166 // Positive fail test case for a method
167 int UtcDaliWheelEventIsNotAltModifier(void)
169 TestApplication application; // Reset all test adapter return codes
171 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
172 DALI_TEST_CHECK(event);
174 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
176 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
180 // Positive test case for a method
181 int UtcDaliWheelEventANDModifer(void)
183 TestApplication application; // Reset all test adapter return codes
185 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
186 DALI_TEST_CHECK(event);
187 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
189 Dali::WheelEvent newEvent = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
190 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsShiftModifier(), TEST_LOCATION);
194 // Positive test case for a method
195 int UtcDaliWheelEventORModifer(void)
197 TestApplication application; // Reset all test adapter return codes
199 Dali::WheelEvent event = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
200 DALI_TEST_CHECK(event);
201 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
203 Dali::WheelEvent newEvent = DevelWheelEvent::New(Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
204 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsAltModifier(), TEST_LOCATION);
208 int UtcDaliWheelEventSignalling(void)
210 TestApplication application; // Reset all test adapter return codes
212 Actor actor = Actor::New();
213 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
214 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
215 application.GetScene().Add(actor);
218 application.SendNotification();
219 application.Render();
221 // Connect to actor's wheel event signal
223 WheelEventReceivedFunctor functor(data);
224 actor.WheelEventSignal().Connect(&application, functor);
226 Vector2 screenCoordinates(10.0f, 10.0f);
227 Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
229 // Emit a wheel signal
230 application.ProcessEvent(event);
231 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
232 DALI_TEST_CHECK(actor == data.wheeledActor);
233 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, data.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
234 DALI_TEST_EQUALS(0, data.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
235 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
236 DALI_TEST_EQUALS(screenCoordinates, data.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
237 DALI_TEST_EQUALS(1, data.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
238 DALI_TEST_EQUALS(1000u, data.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
241 // Emit a wheel signal where the actor is not present, will hit the root actor though
242 Actor rootActor(application.GetScene().GetRootLayer());
244 // Connect to root actor's wheel event signal
246 WheelEventReceivedFunctor rootFunctor(rootData); // Consumes signal
247 rootActor.WheelEventSignal().Connect(&application, rootFunctor);
249 screenCoordinates.x = screenCoordinates.y = 300.0f;
250 Integration::WheelEvent newEvent(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
251 application.ProcessEvent(newEvent);
252 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
253 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
254 DALI_TEST_CHECK(rootActor == rootData.wheeledActor);
255 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, rootData.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
256 DALI_TEST_EQUALS(0, rootData.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
257 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
258 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
259 DALI_TEST_EQUALS(1, rootData.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
260 DALI_TEST_EQUALS(1000u, rootData.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
262 // Remove actor from the scene
263 application.GetScene().Remove(actor);
266 application.SendNotification();
267 application.Render();
269 // Emit a move at the same point, we should not be signalled.
270 application.ProcessEvent(event);
271 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);