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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali/integration-api/events/wheel-event-integ.h>
22 #include <dali/devel-api/events/wheel-event-devel.h>
23 #include <dali-test-suite-utils.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;
37 // Stores data that is populated in the callback and will be read by the TET cases
41 : 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 ) : signalData( data ) { }
62 bool operator()( Actor actor, const WheelEvent& wheelEvent )
64 signalData.functorCalled = true;
65 signalData.receivedWheelEvent = wheelEvent;
66 signalData.wheeledActor = actor;
71 SignalData& signalData;
74 } // anonymous namespace
76 int UtcDaliWheelEventConstructor(void)
78 TestApplication application; // Reset all test adapter return codes
80 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
81 DALI_TEST_CHECK( event );
83 DALI_TEST_EQUALS(Dali::WheelEvent::MOUSE_WHEEL, event.GetType(), TEST_LOCATION); // check type
84 DALI_TEST_EQUALS(1, event.GetDirection(), TEST_LOCATION); // check direction
85 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check modifier
86 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.GetPoint(), TEST_LOCATION); // check modifier
87 DALI_TEST_EQUALS(1, event.GetDelta(), TEST_LOCATION); // check modifier
88 DALI_TEST_EQUALS(1000u, event.GetTime(), TEST_LOCATION); // check modifier
92 // Positive test case for a method
93 int UtcDaliWheelEventIsShiftModifier(void)
95 TestApplication application; // Reset all test adapter return codes
97 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
98 DALI_TEST_CHECK( event );
100 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
102 DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
107 // Positive test case for a method
108 int UtcDaliWheelEventIsCtrlModifier(void)
110 TestApplication application; // Reset all test adapter return codes
112 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
113 DALI_TEST_CHECK( event );
115 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION);
117 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
121 // Positive test case for a method
122 int UtcDaliWheelEventIsAltModifier(void)
124 TestApplication application; // Reset all test adapter return codes
126 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
127 DALI_TEST_CHECK( event );
129 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION);
131 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
135 // Positive fail test case for a method
136 int UtcDaliWheelEventIsNotShiftModifier(void)
138 TestApplication application; // Reset all test adapter return codes
140 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
141 DALI_TEST_CHECK( event );
143 DALI_TEST_EQUALS(CTRL_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
145 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
149 // Positive fail test case for a method
150 int UtcDaliWheelEventIsNotCtrlModifier(void)
152 TestApplication application; // Reset all test adapter return codes
154 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
155 DALI_TEST_CHECK( event );
157 DALI_TEST_EQUALS(ALT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
159 DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
163 // Positive fail test case for a method
164 int UtcDaliWheelEventIsNotAltModifier(void)
166 TestApplication application; // Reset all test adapter return codes
168 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
169 DALI_TEST_CHECK( event );
171 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.GetModifiers(), TEST_LOCATION); // check different modifier used
173 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
177 // Positive test case for a method
178 int UtcDaliWheelEventANDModifer(void)
180 TestApplication application; // Reset all test adapter return codes
182 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
183 DALI_TEST_CHECK( event );
184 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
186 Dali::WheelEvent newEvent = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
187 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsShiftModifier(), TEST_LOCATION);
191 // Positive test case for a method
192 int UtcDaliWheelEventORModifer(void)
194 TestApplication application; // Reset all test adapter return codes
196 Dali::WheelEvent event = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
197 DALI_TEST_CHECK( event );
198 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
200 Dali::WheelEvent newEvent = DevelWheelEvent::New( Dali::WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2( 1.0f, 1.0f ), 1, 1000u );
201 DALI_TEST_EQUALS(false, newEvent.IsCtrlModifier() && newEvent.IsAltModifier(), TEST_LOCATION);
205 int UtcDaliWheelEventSignalling(void)
207 TestApplication application; // Reset all test adapter return codes
209 Actor actor = Actor::New();
210 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
211 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
212 application.GetScene().Add(actor);
215 application.SendNotification();
216 application.Render();
218 // Connect to actor's wheel event signal
220 WheelEventReceivedFunctor functor( data );
221 actor.WheelEventSignal().Connect( &application, functor );
223 Vector2 screenCoordinates( 10.0f, 10.0f );
224 Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
226 // Emit a wheel signal
227 application.ProcessEvent( event );
228 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
229 DALI_TEST_CHECK( actor == data.wheeledActor );
230 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, data.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
231 DALI_TEST_EQUALS(0, data.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
232 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
233 DALI_TEST_EQUALS(screenCoordinates, data.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
234 DALI_TEST_EQUALS(1, data.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
235 DALI_TEST_EQUALS(1000u, data.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
238 // Emit a wheel signal where the actor is not present, will hit the root actor though
239 Actor rootActor( application.GetScene().GetRootLayer() );
241 // Connect to root actor's wheel event signal
243 WheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
244 rootActor.WheelEventSignal().Connect( &application, rootFunctor );
246 screenCoordinates.x = screenCoordinates.y = 300.0f;
247 Integration::WheelEvent newEvent(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
248 application.ProcessEvent( newEvent );
249 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
250 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
251 DALI_TEST_CHECK( rootActor == rootData.wheeledActor );
252 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, rootData.receivedWheelEvent.GetType(), TEST_LOCATION); // check type
253 DALI_TEST_EQUALS(0, rootData.receivedWheelEvent.GetDirection(), TEST_LOCATION); // check direction
254 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedWheelEvent.GetModifiers(), TEST_LOCATION); // check modifier
255 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedWheelEvent.GetPoint(), TEST_LOCATION); // check modifier
256 DALI_TEST_EQUALS(1, rootData.receivedWheelEvent.GetDelta(), TEST_LOCATION); // check modifier
257 DALI_TEST_EQUALS(1000u, rootData.receivedWheelEvent.GetTime(), TEST_LOCATION); // check modifier
259 // Remove actor from the scene
260 application.GetScene().Remove( actor );
263 application.SendNotification();
264 application.Render();
266 // Emit a move at the same point, we should not be signalled.
267 application.ProcessEvent( event );
268 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );