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.
23 #include <dali/dali.h>
24 #include <dali-test-suite-utils.h>
25 #include <tilt-sensor-impl.h>
31 static const float ROTATION_EPSILON = 0.0001f;
34 * Helper to test whether timeout or tilt signal is received first
36 struct SignalHelper : public ConnectionTracker
39 : mTiltSignalReceived( false ),
40 mTimeoutOccurred( false )
44 void OnTilted(const TiltSensor& sensor)
46 tet_printf("tilted signal received\n");
48 mTiltSignalReceived = true;
50 // quit the main loop to continue test
51 //ecore_main_loop_quit();
56 tet_printf("timeout occurred\n");
58 mTimeoutOccurred = true;
60 // quit the main loop to continue test
61 //ecore_main_loop_quit();
66 bool mTiltSignalReceived; // True if tilted signal was received
67 bool mTimeoutOccurred; // True if timeout occured
70 TiltSensor GetTiltSensor()
72 return Internal::Adaptor::TiltSensor::New();
75 bool ecore_timer_running = false;
76 Ecore_Task_Cb timer_callback_func=NULL;
77 const void* timer_callback_data=NULL;
78 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
82 Ecore_Timer* ecore_timer_add(double in,
86 ecore_timer_running = true;
87 timer_callback_func = func;
88 timer_callback_data = data;
90 return (Ecore_Timer*)timerId;
93 void* ecore_timer_del(Ecore_Timer *timer)
95 ecore_timer_running = false;
96 timer_callback_func = NULL;
104 void tilt_sensor_startup(void)
108 void tilt_sensor_cleanup(void)
113 int UtcDaliTiltSensorStart(void)
115 TestApplication application;
117 tet_infoline("UtcDaliTiltSensorStart");
119 TiltSensor sensor = GetTiltSensor();
120 DALI_TEST_CHECK( sensor );
123 DALI_TEST_CHECK( sensor.IsStarted() );
128 int UtcDaliTiltSensorStop(void)
130 TestApplication application;
132 tet_infoline("UtcDaliTiltSensorStop");
134 TiltSensor sensor = GetTiltSensor();
135 DALI_TEST_CHECK( sensor );
138 DALI_TEST_CHECK( sensor.IsStarted() );
141 DALI_TEST_CHECK( !sensor.IsStarted() );
145 int UtcDaliTiltSensorIsStarted(void)
147 TestApplication application;
149 tet_infoline("UtcDaliTiltSensorIsStarted");
151 TiltSensor sensor = GetTiltSensor();
152 DALI_TEST_CHECK( sensor );
154 // Should be disabled by default
155 DALI_TEST_CHECK( !sensor.IsStarted() );
159 int UtcDaliTiltSensorGetRoll(void)
161 TestApplication application;
163 tet_infoline("UtcDaliTiltSensorGetRoll");
165 TiltSensor sensor = GetTiltSensor();
166 DALI_TEST_CHECK( sensor );
168 float roll = sensor.GetRoll();
169 DALI_TEST_CHECK( roll <= 1.0f && roll >= -1.0f ); // range check
173 int UtcDaliTiltSensorGetPitch(void)
175 TestApplication application;
177 tet_infoline("UtcDaliTiltSensorGetPitch");
179 TiltSensor sensor = GetTiltSensor();
180 DALI_TEST_CHECK( sensor );
182 float pitch = sensor.GetPitch();
183 DALI_TEST_CHECK( pitch <= 1.0f && pitch >= -1.0f ); // range check
187 int UtcDaliTiltSensorGetRotation(void)
189 TestApplication application;
191 tet_infoline("UtcDaliTiltSensorGetRotation");
193 TiltSensor sensor = GetTiltSensor();
194 DALI_TEST_CHECK( sensor );
196 Quaternion rotation = sensor.GetRotation();
198 Radian roll( sensor.GetRoll() );
199 Radian pitch( sensor.GetPitch() );
201 Quaternion expectedRotation = Quaternion( roll * Math::PI * -0.5f, Vector3::YAXIS ) *
202 Quaternion( pitch * Math::PI * -0.5f, Vector3::XAXIS );
204 DALI_TEST_EQUALS( rotation, expectedRotation, ROTATION_EPSILON, TEST_LOCATION );
209 int UtcDaliTiltSensorSignalTilted(void)
211 TestApplication application;
213 tet_infoline("UtcDaliTiltSensorSignalTilted");
215 TiltSensor sensor = GetTiltSensor();
216 DALI_TEST_CHECK( sensor );
219 Radian angle(Degree(-45));
220 //Setting a negative threshold for testing purpose
221 sensor.SetRotationThreshold( angle );
226 int UtcDaliTiltSensorSetUpdateFrequency(void)
228 TestApplication application;
230 tet_infoline("UtcDaliTiltSensorSetUpdateFrequency");
232 TiltSensor sensor = GetTiltSensor();
233 DALI_TEST_CHECK( sensor );
234 sensor.SetUpdateFrequency( 1.0f/*hertz*/ );
235 DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 1.0f, TEST_LOCATION );
237 sensor.SetUpdateFrequency( 60.0f/*hertz*/ );
238 DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 60.0f, TEST_LOCATION );
244 int UtcDaliTiltSensorSetRotationThreshold01(void)
246 TestApplication application;
248 tet_infoline("UtcDaliTiltSensorSetRotationThreshold01");
250 TiltSensor sensor = GetTiltSensor();
251 DALI_TEST_CHECK( sensor );
254 Radian angle(Degree(-45));
255 sensor.SetRotationThreshold( angle );
256 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );
259 sensor.SetRotationThreshold( angle );
260 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );