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/public-api/dali-core.h>
21 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
22 #include <dali-test-suite-utils.h>
29 // Key Event Test references
30 const static unsigned int SHIFT_MODIFIER = 0x1;
31 const static unsigned int CTRL_MODIFIER = 0x2;
32 const static unsigned int ALT_MODIFIER = 0x4;
33 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)
45 functorCalled = false;
47 receivedMouseWheelEvent.direction = 0;
48 receivedMouseWheelEvent.modifiers = 0;
49 receivedMouseWheelEvent.point = Vector2::ZERO;
50 receivedMouseWheelEvent.z = 0;
51 receivedMouseWheelEvent.timeStamp = 0;
53 mouseWheeledActor.Reset();
57 MouseWheelEvent receivedMouseWheelEvent;
58 Actor mouseWheeledActor;
61 // Functor that sets the data when called
62 struct MouseWheelEventReceivedFunctor
64 MouseWheelEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
66 bool operator()( Actor actor, const MouseWheelEvent& mouseWheelEvent )
68 signalData.functorCalled = true;
69 signalData.receivedMouseWheelEvent = mouseWheelEvent;
70 signalData.mouseWheeledActor = actor;
75 SignalData& signalData;
78 } // anonymous namespace
80 int UtcDaliMouseWheelEventConstructor(void)
82 TestApplication application; // Reset all test adapter return codes
84 MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u); // coustruct a mouse wheel event
86 DALI_TEST_EQUALS(1, event.direction, TEST_LOCATION); // check direction
87 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check modifier
88 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.point, TEST_LOCATION); // check modifier
89 DALI_TEST_EQUALS(1, event.z, TEST_LOCATION); // check modifier
90 DALI_TEST_EQUALS(1000u, event.timeStamp, TEST_LOCATION); // check modifier
94 // Positive test case for a method
95 int UtcDaliMouseWheelEventIsShiftModifier(void)
97 TestApplication application; // Reset all test adapter return codes
99 MouseWheelEvent event;
100 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
102 event.modifiers = SHIFT_MODIFIER; // Set to Shift Modifier
104 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
106 DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
111 // Positive test case for a method
112 int UtcDaliMouseWheelEventIsCtrlModifier(void)
114 TestApplication application; // Reset all test adapter return codes
116 MouseWheelEvent event;
117 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
119 event.modifiers = CTRL_MODIFIER; // Set to Ctrl Modifier
121 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
123 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
127 // Positive test case for a method
128 int UtcDaliMouseWheelEventIsAltModifier(void)
130 TestApplication application; // Reset all test adapter return codes
132 MouseWheelEvent event;
133 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
135 event.modifiers = ALT_MODIFIER; // Set to Alt Modifier
137 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
139 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
143 // Positive fail test case for a method
144 int UtcDaliMouseWheelEventIsNotShiftModifier(void)
146 TestApplication application; // Reset all test adapter return codes
148 MouseWheelEvent event(1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
150 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
152 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
156 // Positive fail test case for a method
157 int UtcDaliMouseWheelEventIsNotCtrlModifier(void)
159 TestApplication application; // Reset all test adapter return codes
161 MouseWheelEvent event(1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
163 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, 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 UtcDaliMouseWheelEventIsNotAltModifier(void)
172 TestApplication application; // Reset all test adapter return codes
174 MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
176 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
178 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
182 // Positive test case for a method
183 int UtcDaliMouseWheelEventANDModifer(void)
185 TestApplication application; // Reset all test adapter return codes
187 MouseWheelEvent event(1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
188 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
190 event.modifiers = SHIFT_MODIFIER;
192 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
196 // Positive test case for a method
197 int UtcDaliMouseWheelEventORModifer(void)
199 TestApplication application; // Reset all test adapter return codes
201 MouseWheelEvent event(1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
202 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
204 event.modifiers = SHIFT_MODIFIER;
206 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsAltModifier(), TEST_LOCATION);
210 int UtcDaliMouseWheelEventSignalling(void)
212 TestApplication application; // Reset all test adapter return codes
214 Actor actor = Actor::New();
215 actor.SetSize(100.0f, 100.0f);
216 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
217 Stage::GetCurrent().Add(actor);
220 application.SendNotification();
221 application.Render();
223 // Connect to actor's mouse wheel event signal
225 MouseWheelEventReceivedFunctor functor( data );
226 actor.MouseWheelEventSignal().Connect( &application, functor );
228 Vector2 screenCoordinates( 10.0f, 10.0f );
229 Integration::MouseWheelEvent event(0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
231 // Emit a mouse wheel signal
232 application.ProcessEvent( event );
233 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
234 DALI_TEST_CHECK( actor == data.mouseWheeledActor );
235 DALI_TEST_EQUALS(0, data.receivedMouseWheelEvent.direction, TEST_LOCATION); // check direction
236 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedMouseWheelEvent.modifiers, TEST_LOCATION); // check modifier
237 DALI_TEST_EQUALS(screenCoordinates, data.receivedMouseWheelEvent.point, TEST_LOCATION); // check modifier
238 DALI_TEST_EQUALS(1, data.receivedMouseWheelEvent.z, TEST_LOCATION); // check modifier
239 DALI_TEST_EQUALS(1000u, data.receivedMouseWheelEvent.timeStamp, TEST_LOCATION); // check modifier
242 // Emit a mouse wheel signal where the actor is not present, will hit the root actor though
243 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
245 // Connect to root actor's mouse wheel event signal
247 MouseWheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
248 rootActor.MouseWheelEventSignal().Connect( &application, rootFunctor );
250 screenCoordinates.x = screenCoordinates.y = 300.0f;
251 Integration::MouseWheelEvent newEvent(0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
252 application.ProcessEvent( newEvent );
253 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
254 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
255 DALI_TEST_CHECK( rootActor == rootData.mouseWheeledActor );
256 DALI_TEST_EQUALS(0, rootData.receivedMouseWheelEvent.direction, TEST_LOCATION); // check direction
257 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedMouseWheelEvent.modifiers, TEST_LOCATION); // check modifier
258 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedMouseWheelEvent.point, TEST_LOCATION); // check modifier
259 DALI_TEST_EQUALS(1, rootData.receivedMouseWheelEvent.z, TEST_LOCATION); // check modifier
260 DALI_TEST_EQUALS(1000u, rootData.receivedMouseWheelEvent.timeStamp, TEST_LOCATION); // check modifier
262 // Remove actor from stage
263 Stage::GetCurrent().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 );