[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-WheelEvent.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/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     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;
53
54     wheeledActor.Reset();
55   }
56
57   bool functorCalled;
58   WheelEvent receivedWheelEvent;
59   Actor wheeledActor;
60 };
61
62 // Functor that sets the data when called
63 struct WheelEventReceivedFunctor
64 {
65   WheelEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
66
67   bool operator()( Actor actor, const WheelEvent& wheelEvent )
68   {
69     signalData.functorCalled = true;
70     signalData.receivedWheelEvent = wheelEvent;
71     signalData.wheeledActor = actor;
72
73     return true;
74   }
75
76   SignalData& signalData;
77 };
78
79 } // anonymous namespace
80
81 int UtcDaliWheelEventConstructor(void)
82 {
83   TestApplication application; // Reset all test adapter return codes
84
85   WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);  // coustruct a wheel event
86
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
93   END_TEST;
94 }
95
96 // Positive test case for a method
97 int UtcDaliWheelEventIsShiftModifier(void)
98 {
99   TestApplication application; // Reset all test adapter return codes
100
101   WheelEvent event;
102   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
103
104   event.modifiers = SHIFT_MODIFIER; // Set to Shift Modifier
105
106   DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
107
108   DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
109
110   END_TEST;
111 }
112
113 // Positive test case for a method
114 int UtcDaliWheelEventIsCtrlModifier(void)
115 {
116   TestApplication application; // Reset all test adapter return codes
117
118   WheelEvent event;
119   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
120
121   event.modifiers = CTRL_MODIFIER; // Set to Ctrl Modifier
122
123   DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
124
125   DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
126   END_TEST;
127 }
128
129 // Positive test case for a method
130 int UtcDaliWheelEventIsAltModifier(void)
131 {
132   TestApplication application; // Reset all test adapter return codes
133
134   WheelEvent event;
135   DALI_TEST_EQUALS(0u, event.modifiers, TEST_LOCATION);
136
137   event.modifiers = ALT_MODIFIER; // Set to Alt Modifier
138
139   DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION); // check able to set
140
141   DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION);  // IsAltModifier
142   END_TEST;
143 }
144
145 // Positive fail test case for a method
146 int UtcDaliWheelEventIsNotShiftModifier(void)
147 {
148   TestApplication application; // Reset all test adapter return codes
149
150   WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, CTRL_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
151
152   DALI_TEST_EQUALS(CTRL_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
153
154   DALI_TEST_EQUALS(false, event.IsShiftModifier(), TEST_LOCATION);
155   END_TEST;
156 }
157
158 // Positive fail test case for a method
159 int UtcDaliWheelEventIsNotCtrlModifier(void)
160 {
161   TestApplication application; // Reset all test adapter return codes
162
163   WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, ALT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
164
165   DALI_TEST_EQUALS(ALT_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
166
167   DALI_TEST_EQUALS(false, event.IsCtrlModifier(), TEST_LOCATION);
168   END_TEST;
169 }
170
171 // Positive fail test case for a method
172 int UtcDaliWheelEventIsNotAltModifier(void)
173 {
174   TestApplication application; // Reset all test adapter return codes
175
176   WheelEvent event(WheelEvent::MOUSE_WHEEL, 1, SHIFT_MODIFIER, Vector2(1.0f, 1.0f), 1, 1000u);
177
178   DALI_TEST_EQUALS(SHIFT_MODIFIER, event.modifiers, TEST_LOCATION);  // check different modifier used
179
180   DALI_TEST_EQUALS(false, event.IsAltModifier(), TEST_LOCATION);
181   END_TEST;
182 }
183
184 // Positive test case for a method
185 int UtcDaliWheelEventANDModifer(void)
186 {
187   TestApplication application; // Reset all test adapter return codes
188
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);
191
192   event.modifiers = SHIFT_MODIFIER;
193
194   DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsShiftModifier(), TEST_LOCATION);
195   END_TEST;
196 }
197
198 // Positive test case for a method
199 int UtcDaliWheelEventORModifer(void)
200 {
201   TestApplication application; // Reset all test adapter return codes
202
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);
205
206   event.modifiers = SHIFT_MODIFIER;
207
208   DALI_TEST_EQUALS(false, event.IsCtrlModifier() && event.IsAltModifier(), TEST_LOCATION);
209   END_TEST;
210 }
211
212 int UtcDaliWheelEventSignalling(void)
213 {
214   TestApplication application; // Reset all test adapter return codes
215
216   Actor actor = Actor::New();
217   actor.SetSize(100.0f, 100.0f);
218   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
219   Stage::GetCurrent().Add(actor);
220
221   // Render and notify
222   application.SendNotification();
223   application.Render();
224
225   // Connect to actor's wheel event signal
226   SignalData data;
227   WheelEventReceivedFunctor functor( data );
228   actor.WheelEventSignal().Connect( &application, functor );
229
230   Vector2 screenCoordinates( 10.0f, 10.0f );
231   Integration::WheelEvent event(Integration::WheelEvent::MOUSE_WHEEL, 0, SHIFT_MODIFIER, screenCoordinates, 1, 1000u);
232
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
243   data.Reset();
244
245   // Emit a wheel signal where the actor is not present, will hit the root actor though
246   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
247
248   // Connect to root actor's wheel event signal
249   SignalData rootData;
250   WheelEventReceivedFunctor rootFunctor( rootData ); // Consumes signal
251   rootActor.WheelEventSignal().Connect( &application, rootFunctor );
252
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
265
266   // Remove actor from stage
267   Stage::GetCurrent().Remove( actor );
268
269   // Render and notify
270   application.SendNotification();
271   application.Render();
272
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 );
276   data.Reset();
277   END_TEST;
278 }