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 <adaptor-test-application.h>
26 #include <tilt-sensor-impl.h>
32 static const float ROTATION_EPSILON = 0.0001f;
35 * Helper to test whether timeout or tilt signal is received first
37 struct SignalHelper : public ConnectionTracker
40 : mTiltSignalReceived( false ),
41 mTimeoutOccurred( false )
45 void OnTilted(const TiltSensor& sensor)
47 tet_printf("tilted signal received\n");
49 mTiltSignalReceived = true;
51 // quit the main loop to continue test
52 //ecore_main_loop_quit();
57 tet_printf("timeout occurred\n");
59 mTimeoutOccurred = true;
61 // quit the main loop to continue test
62 //ecore_main_loop_quit();
67 bool mTiltSignalReceived; // True if tilted signal was received
68 bool mTimeoutOccurred; // True if timeout occured
71 TiltSensor GetTiltSensor()
73 return Internal::Adaptor::TiltSensor::New();
76 bool ecore_timer_running = false;
77 Ecore_Task_Cb timer_callback_func=NULL;
78 const void* timer_callback_data=NULL;
79 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
83 Ecore_Timer* ecore_timer_add(double in,
87 ecore_timer_running = true;
88 timer_callback_func = func;
89 timer_callback_data = data;
91 return (Ecore_Timer*)timerId;
94 void* ecore_timer_del(Ecore_Timer *timer)
96 ecore_timer_running = false;
97 timer_callback_func = NULL;
105 void tilt_sensor_startup(void)
109 void tilt_sensor_cleanup(void)
114 int UtcDaliTiltSensorStart(void)
116 AdaptorTestApplication application;
118 tet_infoline("UtcDaliTiltSensorStart");
120 TiltSensor sensor = GetTiltSensor();
121 DALI_TEST_CHECK( sensor );
124 DALI_TEST_CHECK( sensor.IsStarted() );
129 int UtcDaliTiltSensorStop(void)
131 AdaptorTestApplication application;
133 tet_infoline("UtcDaliTiltSensorStop");
135 TiltSensor sensor = GetTiltSensor();
136 DALI_TEST_CHECK( sensor );
139 DALI_TEST_CHECK( sensor.IsStarted() );
142 DALI_TEST_CHECK( !sensor.IsStarted() );
146 int UtcDaliTiltSensorIsStarted(void)
148 AdaptorTestApplication application;
150 tet_infoline("UtcDaliTiltSensorIsStarted");
152 TiltSensor sensor = GetTiltSensor();
153 DALI_TEST_CHECK( sensor );
155 // Should be disabled by default
156 DALI_TEST_CHECK( !sensor.IsStarted() );
160 int UtcDaliTiltSensorGetRoll(void)
162 AdaptorTestApplication application;
164 tet_infoline("UtcDaliTiltSensorGetRoll");
166 TiltSensor sensor = GetTiltSensor();
167 DALI_TEST_CHECK( sensor );
169 float roll = sensor.GetRoll();
170 DALI_TEST_CHECK( roll <= 1.0f && roll >= -1.0f ); // range check
174 int UtcDaliTiltSensorGetPitch(void)
176 AdaptorTestApplication application;
178 tet_infoline("UtcDaliTiltSensorGetPitch");
180 TiltSensor sensor = GetTiltSensor();
181 DALI_TEST_CHECK( sensor );
183 float pitch = sensor.GetPitch();
184 DALI_TEST_CHECK( pitch <= 1.0f && pitch >= -1.0f ); // range check
188 int UtcDaliTiltSensorGetRotation(void)
190 AdaptorTestApplication application;
192 tet_infoline("UtcDaliTiltSensorGetRotation");
194 TiltSensor sensor = GetTiltSensor();
195 DALI_TEST_CHECK( sensor );
197 Quaternion rotation = sensor.GetRotation();
199 Radian roll( sensor.GetRoll() );
200 Radian pitch( sensor.GetPitch() );
202 Quaternion expectedRotation = Quaternion( roll * Math::PI * -0.5f, Vector3::YAXIS ) *
203 Quaternion( pitch * Math::PI * -0.5f, Vector3::XAXIS );
205 DALI_TEST_EQUALS( rotation, expectedRotation, ROTATION_EPSILON, TEST_LOCATION );
210 int UtcDaliTiltSensorSignalTilted(void)
212 AdaptorTestApplication application;
214 tet_infoline("UtcDaliTiltSensorSignalTilted");
216 TiltSensor sensor = GetTiltSensor();
217 DALI_TEST_CHECK( sensor );
220 Radian angle(Degree(-45));
221 //Setting a negative threshold for testing purpose
222 sensor.SetRotationThreshold( angle );
227 int UtcDaliTiltSensorSetUpdateFrequency(void)
229 AdaptorTestApplication application;
231 tet_infoline("UtcDaliTiltSensorSetUpdateFrequency");
233 TiltSensor sensor = GetTiltSensor();
234 DALI_TEST_CHECK( sensor );
235 sensor.SetUpdateFrequency( 1.0f/*hertz*/ );
236 DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 1.0f, TEST_LOCATION );
238 sensor.SetUpdateFrequency( 60.0f/*hertz*/ );
239 DALI_TEST_EQUALS( sensor.GetUpdateFrequency(), 60.0f, TEST_LOCATION );
245 int UtcDaliTiltSensorSetRotationThreshold01(void)
247 AdaptorTestApplication application;
249 tet_infoline("UtcDaliTiltSensorSetRotationThreshold01");
251 TiltSensor sensor = GetTiltSensor();
252 DALI_TEST_CHECK( sensor );
255 Radian angle(Degree(-45));
256 sensor.SetRotationThreshold( angle );
257 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );
260 sensor.SetRotationThreshold( angle );
261 DALI_TEST_EQUALS( sensor.GetRotationThreshold(), angle, TEST_LOCATION );