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.
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>
33 static const float ROTATION_EPSILON = 0.0001f;
36 * Helper to test whether timeout or tilt signal is received first
38 struct SignalHelper : public ConnectionTracker
41 : mTiltSignalReceived( false ),
42 mTimeoutOccurred( false )
46 void OnTilted(const TiltSensor& sensor)
48 tet_printf("tilted signal received\n");
50 mTiltSignalReceived = true;
52 // quit the main loop to continue test
53 //ecore_main_loop_quit();
58 tet_printf("timeout occurred\n");
60 mTimeoutOccurred = true;
62 // quit the main loop to continue test
63 //ecore_main_loop_quit();
68 bool mTiltSignalReceived; // True if tilted signal was received
69 bool mTimeoutOccurred; // True if timeout occured
72 TiltSensor GetTiltSensor()
74 return Dali::TiltSensor(Dali::Internal::Adaptor::TiltSensorFactory::Create());
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
84 Ecore_Timer* ecore_timer_add(double in,
88 ecore_timer_running = true;
89 timer_callback_func = func;
90 timer_callback_data = data;
92 return (Ecore_Timer*)timerId;
95 void* ecore_timer_del(Ecore_Timer *timer)
97 ecore_timer_running = false;
98 timer_callback_func = NULL;
106 void tilt_sensor_startup(void)
110 void tilt_sensor_cleanup(void)
115 int UtcDaliTiltSensorStart(void)
117 AdaptorTestApplication application;
119 tet_infoline("UtcDaliTiltSensorStart");
121 TiltSensor sensor = GetTiltSensor();
122 DALI_TEST_CHECK( sensor );
125 DALI_TEST_CHECK( sensor.IsStarted() );
130 int UtcDaliTiltSensorStop(void)
132 AdaptorTestApplication application;
134 tet_infoline("UtcDaliTiltSensorStop");
136 TiltSensor sensor = GetTiltSensor();
137 DALI_TEST_CHECK( sensor );
140 DALI_TEST_CHECK( sensor.IsStarted() );
143 DALI_TEST_CHECK( !sensor.IsStarted() );
147 int UtcDaliTiltSensorIsStarted(void)
149 AdaptorTestApplication application;
151 tet_infoline("UtcDaliTiltSensorIsStarted");
153 TiltSensor sensor = GetTiltSensor();
154 DALI_TEST_CHECK( sensor );
156 // Should be disabled by default
157 DALI_TEST_CHECK( !sensor.IsStarted() );
161 int UtcDaliTiltSensorGetRoll(void)
163 AdaptorTestApplication application;
165 tet_infoline("UtcDaliTiltSensorGetRoll");
167 TiltSensor sensor = GetTiltSensor();
168 DALI_TEST_CHECK( sensor );
170 float roll = sensor.GetRoll();
171 DALI_TEST_CHECK( roll <= 1.0f && roll >= -1.0f ); // range check
175 int UtcDaliTiltSensorGetPitch(void)
177 AdaptorTestApplication application;
179 tet_infoline("UtcDaliTiltSensorGetPitch");
181 TiltSensor sensor = GetTiltSensor();
182 DALI_TEST_CHECK( sensor );
184 float pitch = sensor.GetPitch();
185 DALI_TEST_CHECK( pitch <= 1.0f && pitch >= -1.0f ); // range check
189 int UtcDaliTiltSensorGetRotation(void)
191 AdaptorTestApplication application;
193 tet_infoline("UtcDaliTiltSensorGetRotation");
195 TiltSensor sensor = GetTiltSensor();
196 DALI_TEST_CHECK( sensor );
198 Quaternion rotation = sensor.GetRotation();
200 Radian roll( sensor.GetRoll() );
201 Radian pitch( sensor.GetPitch() );
203 Quaternion expectedRotation = Quaternion( roll * Math::PI * -0.5f, Vector3::YAXIS ) *
204 Quaternion( pitch * Math::PI * -0.5f, Vector3::XAXIS );
206 DALI_TEST_EQUALS( rotation, expectedRotation, ROTATION_EPSILON, TEST_LOCATION );
211 int UtcDaliTiltSensorSignalTilted(void)
213 AdaptorTestApplication application;
215 tet_infoline("UtcDaliTiltSensorSignalTilted");
217 TiltSensor sensor = GetTiltSensor();
218 DALI_TEST_CHECK( sensor );
221 Radian angle(Degree(-45));
222 //Setting a negative threshold for testing purpose
223 sensor.SetRotationThreshold( angle );
228 int UtcDaliTiltSensorSetUpdateFrequency(void)
230 AdaptorTestApplication application;
232 tet_infoline("UtcDaliTiltSensorSetUpdateFrequency");
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 );
239 sensor.SetUpdateFrequency( 60.0f/*hertz*/ );
240 DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 60.0f, TEST_LOCATION );
246 int UtcDaliTiltSensorSetRotationThreshold01(void)
248 AdaptorTestApplication application;
250 tet_infoline("UtcDaliTiltSensorSetRotationThreshold01");
252 TiltSensor sensor = GetTiltSensor();
253 DALI_TEST_CHECK( sensor );
256 Radian angle(Degree(-45));
257 sensor.SetRotationThreshold( angle );
258 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );
261 sensor.SetRotationThreshold( angle );
262 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );