Improved pan gesture prediction
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-MouseWheelEvent.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
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>
23
24 using namespace Dali;
25
26 namespace
27 {
28
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;
34
35
36 // Stores data that is populated in the callback and will be read by the TET cases
37 struct SignalData
38 {
39   SignalData()
40   : functorCalled(false)
41   {}
42
43   void Reset()
44   {
45     functorCalled = false;
46
47     receivedMouseWheelEvent.direction = 0;
48     receivedMouseWheelEvent.modifiers = 0;
49     receivedMouseWheelEvent.point = Vector2::ZERO;
50     receivedMouseWheelEvent.z = 0;
51     receivedMouseWheelEvent.timeStamp = 0;
52
53     mouseWheeledActor.Reset();
54   }
55
56   bool functorCalled;
57   MouseWheelEvent receivedMouseWheelEvent;
58   Actor mouseWheeledActor;
59 };
60
61 // Functor that sets the data when called
62 struct MouseWheelEventReceivedFunctor
63 {
64   MouseWheelEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
65
66   bool operator()( Actor actor, const MouseWheelEvent& mouseWheelEvent )
67   {
68     signalData.functorCalled = true;
69     signalData.receivedMouseWheelEvent = mouseWheelEvent;
70     signalData.mouseWheeledActor = actor;
71
72     return true;
73   }
74
75   SignalData& signalData;
76 };
77
78 } // anonymous namespace
79
80 int UtcDaliMouseWheelEventConstructor(void)
81 {
82   TestApplication application; // Reset all test adapter return codes
83
84   MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);  // coustruct a mouse wheel event
85
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
91   END_TEST;
92 }
93
94 // Positive test case for a method
95 int UtcDaliMouseWheelEventIsShiftModifier(void)
96 {
97   TestApplication application; // Reset all test adapter return codes
98
99   MouseWheelEvent event;
100   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
101
102   event.modifiers = SHIFT_MODIFIER; // Set to Shift Modifier
103
104   DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
105
106   DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
107
108   END_TEST;
109 }
110
111 // Positive test case for a method
112 int UtcDaliMouseWheelEventIsCtrlModifier(void)
113 {
114   TestApplication application; // Reset all test adapter return codes
115
116   MouseWheelEvent event;
117   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
118
119   event.modifiers = CTRL_MODIFIER; // Set to Ctrl Modifier
120
121   DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
122
123   DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
124   END_TEST;
125 }
126
127 // Positive test case for a method
128 int UtcDaliMouseWheelEventIsAltModifier(void)
129 {
130   TestApplication application; // Reset all test adapter return codes
131
132   MouseWheelEvent event;
133   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
134
135   event.modifiers = ALT_MODIFIER; // Set to Alt Modifier
136
137   DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
138
139   DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION);  // IsAltModifier
140   END_TEST;
141 }
142
143 // Positive fail test case for a method
144 int UtcDaliMouseWheelEventIsNotShiftModifier(void)
145 {
146   TestApplication application; // Reset all test adapter return codes
147
148   MouseWheelEvent event(1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
149
150   DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
151
152   DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
153   END_TEST;
154 }
155
156 // Positive fail test case for a method
157 int UtcDaliMouseWheelEventIsNotCtrlModifier(void)
158 {
159   TestApplication application; // Reset all test adapter return codes
160
161   MouseWheelEvent event(1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
162
163   DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
164
165   DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
166   END_TEST;
167 }
168
169 // Positive fail test case for a method
170 int UtcDaliMouseWheelEventIsNotAltModifier(void)
171 {
172   TestApplication application; // Reset all test adapter return codes
173
174   MouseWheelEvent event(1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
175
176   DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
177
178   DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
179   END_TEST;
180 }
181
182 // Positive test case for a method
183 int UtcDaliMouseWheelEventANDModifer(void)
184 {
185   TestApplication application; // Reset all test adapter return codes
186
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);
189
190   event.modifiers = SHIFT_MODIFIER;
191
192   DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
193   END_TEST;
194 }
195
196 // Positive test case for a method
197 int UtcDaliMouseWheelEventORModifer(void)
198 {
199   TestApplication application; // Reset all test adapter return codes
200
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);
203
204   event.modifiers = SHIFT_MODIFIER;
205
206   DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsAltModifier(), TEST_LOCATION);
207   END_TEST;
208 }
209
210 int UtcDaliMouseWheelEventSignalling(void)
211 {
212   TestApplication application; // Reset all test adapter return codes
213
214   Actor actor = Actor::New();
215   actor.SetSize(100.0f, 100.0f);
216   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
217   Stage::GetCurrent().Add(actor);
218
219   // Render and notify
220   application.SendNotification();
221   application.Render();
222
223   // Connect to actor's mouse wheel event signal
224   SignalData data;
225   MouseWheelEventReceivedFunctor functor( data );
226   actor.MouseWheelEventSignal().Connect( &application, functor );
227
228   Vector2 screenCoordinates( 10.0f, 10.0f );
229   Integration::MouseWheelEvent event(0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
230
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
240   data.Reset();
241
242   // Emit a mouse wheel signal where the actor is not present, will hit the root actor though
243   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
244
245   // Connect to root actor's mouse wheel event signal
246   SignalData rootData;
247   MouseWheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
248   rootActor.MouseWheelEventSignal().Connect( &application, rootFunctor );
249
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
261
262   // Remove actor from stage
263   Stage::GetCurrent().Remove( actor );
264
265   // Render and notify
266   application.SendNotification();
267   application.Render();
268
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 );
272   data.Reset();
273   END_TEST;
274 }