Revert "[Tizen] Add DALi Autofill implementation"
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / utc-Dali-TiltSensor.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
20 #include <stdlib.h>
21 #include <stdint.h>
22 #include <dali/dali.h>
23 #include <dali-test-suite-utils.h>
24 #include <adaptor-test-application.h>
25 #include <dali/internal/sensor/common/tilt-sensor-impl.h>
26 #include <dali/internal/sensor/common/tilt-sensor-factory.h>
27 #include <dali/internal/system/linux/dali-ecore.h>
28
29 using namespace Dali;
30
31 namespace
32 {
33 static const float ROTATION_EPSILON = 0.0001f;
34
35 /**
36  * Helper to test whether timeout or tilt signal is received first
37  */
38 struct SignalHelper : public ConnectionTracker
39 {
40   SignalHelper()
41   : mTiltSignalReceived( false ),
42     mTimeoutOccurred( false )
43   {
44   }
45
46   void OnTilted(const TiltSensor& sensor)
47   {
48     tet_printf("tilted signal received\n");
49
50     mTiltSignalReceived = true;
51
52     // quit the main loop to continue test
53     //ecore_main_loop_quit();
54   }
55
56   bool OnTimeout()
57   {
58     tet_printf("timeout occurred\n");
59
60     mTimeoutOccurred = true;
61
62     // quit the main loop to continue test
63     //ecore_main_loop_quit();
64
65     return false;
66   }
67
68   bool mTiltSignalReceived; // True if tilted signal was received
69   bool mTimeoutOccurred;    // True if timeout occured
70 };
71
72 TiltSensor GetTiltSensor()
73 {
74   return Dali::TiltSensor(Dali::Internal::Adaptor::TiltSensorFactory::Create());
75 }
76
77 bool ecore_timer_running = false;
78 Ecore_Task_Cb timer_callback_func=NULL;
79 const void* timer_callback_data=NULL;
80 intptr_t timerId = 8; // intptr_t has the same size as a pointer and is platform independent so this can be returned as a pointer in ecore_timer_add below without compilation warnings
81 }// anon namespace
82 extern "C"
83 {
84 Ecore_Timer* ecore_timer_add(double in,
85                              Ecore_Task_Cb func,
86                              const void   *data)
87 {
88   ecore_timer_running = true;
89   timer_callback_func = func;
90   timer_callback_data = data;
91   timerId+=8;
92   return (Ecore_Timer*)timerId;
93 }
94
95 void* ecore_timer_del(Ecore_Timer *timer)
96 {
97   ecore_timer_running = false;
98   timer_callback_func = NULL;
99   return NULL;
100 }
101
102 }
103
104
105
106 void tilt_sensor_startup(void)
107 {
108 }
109
110 void tilt_sensor_cleanup(void)
111 {
112 }
113
114
115 int UtcDaliTiltSensorStart(void)
116 {
117   AdaptorTestApplication application;
118
119   tet_infoline("UtcDaliTiltSensorStart");
120
121   TiltSensor sensor = GetTiltSensor();
122   DALI_TEST_CHECK( sensor );
123
124   sensor.Start();
125   DALI_TEST_CHECK( sensor.IsStarted() );
126
127   END_TEST;
128 }
129
130 int UtcDaliTiltSensorStop(void)
131 {
132   AdaptorTestApplication application;
133
134   tet_infoline("UtcDaliTiltSensorStop");
135
136   TiltSensor sensor = GetTiltSensor();
137   DALI_TEST_CHECK( sensor );
138
139   sensor.Start();
140   DALI_TEST_CHECK( sensor.IsStarted() );
141
142   sensor.Stop();
143   DALI_TEST_CHECK( !sensor.IsStarted() );
144   END_TEST;
145 }
146
147 int UtcDaliTiltSensorIsStarted(void)
148 {
149   AdaptorTestApplication application;
150
151   tet_infoline("UtcDaliTiltSensorIsStarted");
152
153   TiltSensor sensor = GetTiltSensor();
154   DALI_TEST_CHECK( sensor );
155
156   // Should be disabled by default
157   DALI_TEST_CHECK( !sensor.IsStarted() );
158   END_TEST;
159 }
160
161 int UtcDaliTiltSensorGetRoll(void)
162 {
163   AdaptorTestApplication application;
164
165   tet_infoline("UtcDaliTiltSensorGetRoll");
166
167   TiltSensor sensor = GetTiltSensor();
168   DALI_TEST_CHECK( sensor );
169
170   float roll = sensor.GetRoll();
171   DALI_TEST_CHECK( roll <= 1.0f && roll >= -1.0f ); // range check
172   END_TEST;
173 }
174
175 int UtcDaliTiltSensorGetPitch(void)
176 {
177   AdaptorTestApplication application;
178
179   tet_infoline("UtcDaliTiltSensorGetPitch");
180
181   TiltSensor sensor = GetTiltSensor();
182   DALI_TEST_CHECK( sensor );
183
184   float pitch = sensor.GetPitch();
185   DALI_TEST_CHECK( pitch <= 1.0f && pitch >= -1.0f ); // range check
186   END_TEST;
187 }
188
189 int UtcDaliTiltSensorGetRotation(void)
190 {
191   AdaptorTestApplication application;
192
193   tet_infoline("UtcDaliTiltSensorGetRotation");
194
195   TiltSensor sensor = GetTiltSensor();
196   DALI_TEST_CHECK( sensor );
197
198   Quaternion rotation = sensor.GetRotation();
199
200   Radian roll( sensor.GetRoll() );
201   Radian pitch( sensor.GetPitch() );
202
203   Quaternion expectedRotation = Quaternion( roll  * Math::PI * -0.5f, Vector3::YAXIS ) *
204                                 Quaternion( pitch * Math::PI * -0.5f, Vector3::XAXIS );
205
206   DALI_TEST_EQUALS( rotation, expectedRotation, ROTATION_EPSILON, TEST_LOCATION );
207   END_TEST;
208 }
209
210
211 int UtcDaliTiltSensorSignalTilted(void)
212 {
213   AdaptorTestApplication application;
214
215   tet_infoline("UtcDaliTiltSensorSignalTilted");
216
217   TiltSensor sensor = GetTiltSensor();
218   DALI_TEST_CHECK( sensor );
219   sensor.Start();
220
221   Radian angle(Degree(-45));
222   //Setting a negative threshold for testing purpose
223   sensor.SetRotationThreshold( angle );
224
225   END_TEST;
226 }
227
228 int UtcDaliTiltSensorSetUpdateFrequency(void)
229 {
230   AdaptorTestApplication application;
231
232   tet_infoline("UtcDaliTiltSensorSetUpdateFrequency");
233
234   TiltSensor sensor = GetTiltSensor();
235   DALI_TEST_CHECK( sensor );
236   sensor.SetUpdateFrequency( 1.0f/*hertz*/ );
237   DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 1.0f, TEST_LOCATION );
238
239   sensor.SetUpdateFrequency( 60.0f/*hertz*/ );
240   DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 60.0f, TEST_LOCATION );
241
242   END_TEST;
243 }
244
245
246 int UtcDaliTiltSensorSetRotationThreshold01(void)
247 {
248   AdaptorTestApplication application;
249
250   tet_infoline("UtcDaliTiltSensorSetRotationThreshold01");
251
252   TiltSensor sensor = GetTiltSensor();
253   DALI_TEST_CHECK( sensor );
254   sensor.Start();
255
256   Radian angle(Degree(-45));
257   sensor.SetRotationThreshold( angle );
258   DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );
259
260   angle = Degree(90);
261   sensor.SetRotationThreshold( angle );
262   DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );
263   END_TEST;
264 }