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/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 receivedWheelEvent.type = WheelEvent::MOUSE_WHEEL;
48 receivedWheelEvent.direction = 0;
49 receivedWheelEvent.modifiers = 0;
50 receivedWheelEvent.point = Vector2::ZERO;
51 receivedWheelEvent.z = 0;
52 receivedWheelEvent.timeStamp = 0;
58 WheelEvent receivedWheelEvent;
62 // Functor that sets the data when called
63 struct WheelEventReceivedFunctor
65 WheelEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
67 bool operator()( Actor actor, const WheelEvent& wheelEvent )
69 signalData.functorCalled = true;
70 signalData.receivedWheelEvent = wheelEvent;
71 signalData.wheeledActor = actor;
76 SignalData& signalData;
79 } // anonymous namespace
81 int UtcDaliWheelEventConstructor(void)
83 TestApplication application; // Reset all test adapter return codes
85 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u); // coustruct a wheel event
87 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, event.type, TEST_LOCATION); // check type
88 DALI_TEST_EQUALS(1, event.direction, TEST_LOCATION); // check direction
89 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check modifier
90 DALI_TEST_EQUALS(Vector2(1.0f, 1.0f), event.point, TEST_LOCATION); // check modifier
91 DALI_TEST_EQUALS(1, event.z, TEST_LOCATION); // check modifier
92 DALI_TEST_EQUALS(1000u, event.timeStamp, TEST_LOCATION); // check modifier
96 // Positive test case for a method
97 int UtcDaliWheelEventIsShiftModifier(void)
99 TestApplication application; // Reset all test adapter return codes
102 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
104 event.modifiers = SHIFT_MODIFIER; // Set to Shift Modifier
106 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
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
119 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
121 event.modifiers = CTRL_MODIFIER; // Set to Ctrl Modifier
123 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
125 DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
129 // Positive test case for a method
130 int UtcDaliWheelEventIsAltModifier(void)
132 TestApplication application; // Reset all test adapter return codes
135 DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
137 event.modifiers = ALT_MODIFIER; // Set to Alt Modifier
139 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
141 DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
145 // Positive fail test case for a method
146 int UtcDaliWheelEventIsNotShiftModifier(void)
148 TestApplication application; // Reset all test adapter return codes
150 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
152 DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
154 DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
158 // Positive fail test case for a method
159 int UtcDaliWheelEventIsNotCtrlModifier(void)
161 TestApplication application; // Reset all test adapter return codes
163 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
165 DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
167 DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
171 // Positive fail test case for a method
172 int UtcDaliWheelEventIsNotAltModifier(void)
174 TestApplication application; // Reset all test adapter return codes
176 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
178 DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check different modifier used
180 DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
184 // Positive test case for a method
185 int UtcDaliWheelEventANDModifer(void)
187 TestApplication application; // Reset all test adapter return codes
189 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
190 DALI_TEST_EQUALS(true, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
192 event.modifiers = SHIFT_MODIFIER;
194 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
198 // Positive test case for a method
199 int UtcDaliWheelEventORModifer(void)
201 TestApplication application; // Reset all test adapter return codes
203 WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_AND_CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
204 DALI_TEST_EQUALS(true, event.IsCtrlModifier() || event.IsAltModifier(), TEST_LOCATION);
206 event.modifiers = SHIFT_MODIFIER;
208 DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsAltModifier(), TEST_LOCATION);
212 int UtcDaliWheelEventSignalling(void)
214 TestApplication application; // Reset all test adapter return codes
216 Actor actor = Actor::New();
217 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
218 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
219 application.GetScene().Add(actor);
222 application.SendNotification();
223 application.Render();
225 // Connect to actor's wheel event signal
227 WheelEventReceivedFunctor functor( data );
228 actor.WheelEventSignal().Connect( &application, functor );
230 Vector2 screenCoordinates( 10.0f, 10.0f );
231 Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
233 // Emit a wheel signal
234 application.ProcessEvent( event );
235 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
236 DALI_TEST_CHECK( actor == data.wheeledActor );
237 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, data.receivedWheelEvent.type, TEST_LOCATION); // check type
238 DALI_TEST_EQUALS(0, data.receivedWheelEvent.direction, TEST_LOCATION); // check direction
239 DALI_TEST_EQUALS(SHIFT_MODIFIER, data.receivedWheelEvent.modifiers, TEST_LOCATION); // check modifier
240 DALI_TEST_EQUALS(screenCoordinates, data.receivedWheelEvent.point, TEST_LOCATION); // check modifier
241 DALI_TEST_EQUALS(1, data.receivedWheelEvent.z, TEST_LOCATION); // check modifier
242 DALI_TEST_EQUALS(1000u, data.receivedWheelEvent.timeStamp, TEST_LOCATION); // check modifier
245 // Emit a wheel signal where the actor is not present, will hit the root actor though
246 Actor rootActor( application.GetScene().GetRootLayer() );
248 // Connect to root actor's wheel event signal
250 WheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
251 rootActor.WheelEventSignal().Connect( &application, rootFunctor );
253 screenCoordinates.x = screenCoordinates.y = 300.0f;
254 Integration::WheelEvent newEvent(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
255 application.ProcessEvent( newEvent );
256 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
257 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
258 DALI_TEST_CHECK( rootActor == rootData.wheeledActor );
259 DALI_TEST_EQUALS(WheelEvent::MOUSE_WHEEL, rootData.receivedWheelEvent.type, TEST_LOCATION); // check type
260 DALI_TEST_EQUALS(0, rootData.receivedWheelEvent.direction, TEST_LOCATION); // check direction
261 DALI_TEST_EQUALS(SHIFT_MODIFIER, rootData.receivedWheelEvent.modifiers, TEST_LOCATION); // check modifier
262 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedWheelEvent.point, TEST_LOCATION); // check modifier
263 DALI_TEST_EQUALS(1, rootData.receivedWheelEvent.z, TEST_LOCATION); // check modifier
264 DALI_TEST_EQUALS(1000u, rootData.receivedWheelEvent.timeStamp, TEST_LOCATION); // check modifier
266 // Remove actor from the scene
267 application.GetScene().Remove( actor );
270 application.SendNotification();
271 application.Render();
273 // Emit a move at the same point, we should not be signalled.
274 application.ProcessEvent( event );
275 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );