2 * Copyright (c) 2014 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/dali.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/mouse-wheel-event-integ.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 receivedMouseWheelEvent.direction = 0;
49 receivedMouseWheelEvent.modifiers = 0;
50 receivedMouseWheelEvent.point = Vector2::ZERO;
51 receivedMouseWheelEvent.z = 0;
52 receivedMouseWheelEvent.timeStamp = 0;
54 mouseWheeledActor = NULL;
58 MouseWheelEvent receivedMouseWheelEvent;
59 Actor mouseWheeledActor;
62 // Functor that sets the data when called
63 struct MouseWheelEventReceivedFunctor
65 MouseWheelEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
67 bool operator()( Actor actor, const MouseWheelEvent& mouseWheelEvent )
69 signalData.functorCalled = true;
70 signalData.receivedMouseWheelEvent = mouseWheelEvent;
71 signalData.mouseWheeledActor = actor;
76 SignalData& signalData;
79 } // anonymous namespace
81 int UtcDaliMouseWheelEventConstructor(void)
83 TestApplication application; // Reset all test adapter return codes
85 MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u); // coustruct a mouse wheel event
87 DALI_TEST_EQUALS(1, event.direction, TEST_LOCATION); // check direction
88 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check modifier
89 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.point, TEST_LOCATION); // check modifier
90 DALI_TEST_EQUALS(1, event.z, TEST_LOCATION); // check modifier
91 DALI_TEST_EQUALS(1000u, event.timeStamp, TEST_LOCATION); // check modifier
95 // Positive test case for a method
96 int UtcDaliMouseWheelEventIsShiftModifier(void)
98 TestApplication application; // Reset all test adapter return codes
100 MouseWheelEvent event;
101 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
103 event.modifiers = SHIFT_MODIFIER; // Set to Shift Modifier
105 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
107 DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
112 // Positive test case for a method
113 int UtcDaliMouseWheelEventIsCtrlModifier(void)
115 TestApplication application; // Reset all test adapter return codes
117 MouseWheelEvent event;
118 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
120 event.modifiers = CTRL_MODIFIER; // Set to Ctrl Modifier
122 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
124 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
128 // Positive test case for a method
129 int UtcDaliMouseWheelEventIsAltModifier(void)
131 TestApplication application; // Reset all test adapter return codes
133 MouseWheelEvent event;
134 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
136 event.modifiers = ALT_MODIFIER; // Set to Alt Modifier
138 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
140 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
144 // Positive fail test case for a method
145 int UtcDaliMouseWheelEventIsNotShiftModifier(void)
147 TestApplication application; // Reset all test adapter return codes
149 MouseWheelEvent event(1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
151 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
153 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
157 // Positive fail test case for a method
158 int UtcDaliMouseWheelEventIsNotCtrlModifier(void)
160 TestApplication application; // Reset all test adapter return codes
162 MouseWheelEvent event(1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
164 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
166 DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
170 // Positive fail test case for a method
171 int UtcDaliMouseWheelEventIsNotAltModifier(void)
173 TestApplication application; // Reset all test adapter return codes
175 MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
177 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
179 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
183 // Positive test case for a method
184 int UtcDaliMouseWheelEventANDModifer(void)
186 TestApplication application; // Reset all test adapter return codes
188 MouseWheelEvent event(1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
189 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
191 event.modifiers = SHIFT_MODIFIER;
193 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
197 // Positive test case for a method
198 int UtcDaliMouseWheelEventORModifer(void)
200 TestApplication application; // Reset all test adapter return codes
202 MouseWheelEvent event(1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
203 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
205 event.modifiers = SHIFT_MODIFIER;
207 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsAltModifier(), TEST_LOCATION);
211 int UtcDaliMouseWheelEventSignalling(void)
213 TestApplication application; // Reset all test adapter return codes
215 Actor actor = Actor::New();
216 actor.SetSize(100.0f, 100.0f);
217 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
218 Stage::GetCurrent().Add(actor);
221 application.SendNotification();
222 application.Render();
224 // Connect to actor's mouse wheel event signal
226 MouseWheelEventReceivedFunctor functor( data );
227 actor.MouseWheelEventSignal().Connect( &application, functor );
229 Vector2 screenCoordinates( 10.0f, 10.0f );
230 Integration::MouseWheelEvent event(0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
232 // Emit a mouse wheel signal
233 application.ProcessEvent( event );
234 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
235 DALI_TEST_CHECK( actor == data.mouseWheeledActor );
236 DALI_TEST_EQUALS(0, data.receivedMouseWheelEvent.direction, TEST_LOCATION); // check direction
237 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedMouseWheelEvent.modifiers, TEST_LOCATION); // check modifier
238 DALI_TEST_EQUALS(screenCoordinates, data.receivedMouseWheelEvent.point, TEST_LOCATION); // check modifier
239 DALI_TEST_EQUALS(1, data.receivedMouseWheelEvent.z, TEST_LOCATION); // check modifier
240 DALI_TEST_EQUALS(1000u, data.receivedMouseWheelEvent.timeStamp, TEST_LOCATION); // check modifier
243 // Emit a mouse wheel signal where the actor is not present, will hit the root actor though
244 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
246 // Connect to root actor's mouse wheel event signal
248 MouseWheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
249 rootActor.MouseWheelEventSignal().Connect( &application, rootFunctor );
251 screenCoordinates.x = screenCoordinates.y = 300.0f;
252 Integration::MouseWheelEvent newEvent(0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
253 application.ProcessEvent( newEvent );
254 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
255 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
256 DALI_TEST_CHECK( rootActor == rootData.mouseWheeledActor );
257 DALI_TEST_EQUALS(0, rootData.receivedMouseWheelEvent.direction, TEST_LOCATION); // check direction
258 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedMouseWheelEvent.modifiers, TEST_LOCATION); // check modifier
259 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedMouseWheelEvent.point, TEST_LOCATION); // check modifier
260 DALI_TEST_EQUALS(1, rootData.receivedMouseWheelEvent.z, TEST_LOCATION); // check modifier
261 DALI_TEST_EQUALS(1000u, rootData.receivedMouseWheelEvent.timeStamp, TEST_LOCATION); // check modifier
263 // Remove actor from stage
264 Stage::GetCurrent().Remove( actor );
267 application.SendNotification();
268 application.Render();
270 // Emit a move at the same point, we should not be signalled.
271 application.ProcessEvent( event );
272 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );