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.
20 #include <adaptor-test-application.h>
21 #include <dali-test-suite-utils.h>
22 #include <dali/dali.h>
23 #include <dali/internal/sensor/common/tilt-sensor-factory.h>
24 #include <dali/internal/sensor/common/tilt-sensor-impl.h>
25 #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;
103 void tilt_sensor_startup(void)
107 void tilt_sensor_cleanup(void)
111 int UtcDaliTiltSensorStart(void)
113 AdaptorTestApplication application;
115 tet_infoline("UtcDaliTiltSensorStart");
117 TiltSensor sensor = GetTiltSensor();
118 DALI_TEST_CHECK(sensor);
121 DALI_TEST_CHECK(sensor.IsStarted());
126 int UtcDaliTiltSensorStop(void)
128 AdaptorTestApplication application;
130 tet_infoline("UtcDaliTiltSensorStop");
132 TiltSensor sensor = GetTiltSensor();
133 DALI_TEST_CHECK(sensor);
136 DALI_TEST_CHECK(sensor.IsStarted());
139 DALI_TEST_CHECK(!sensor.IsStarted());
143 int UtcDaliTiltSensorIsStarted(void)
145 AdaptorTestApplication application;
147 tet_infoline("UtcDaliTiltSensorIsStarted");
149 TiltSensor sensor = GetTiltSensor();
150 DALI_TEST_CHECK(sensor);
152 // Should be disabled by default
153 DALI_TEST_CHECK(!sensor.IsStarted());
157 int UtcDaliTiltSensorGetRoll(void)
159 AdaptorTestApplication application;
161 tet_infoline("UtcDaliTiltSensorGetRoll");
163 TiltSensor sensor = GetTiltSensor();
164 DALI_TEST_CHECK(sensor);
166 float roll = sensor.GetRoll();
167 DALI_TEST_CHECK(roll <= 1.0f && roll >= -1.0f); // range check
171 int UtcDaliTiltSensorGetPitch(void)
173 AdaptorTestApplication application;
175 tet_infoline("UtcDaliTiltSensorGetPitch");
177 TiltSensor sensor = GetTiltSensor();
178 DALI_TEST_CHECK(sensor);
180 float pitch = sensor.GetPitch();
181 DALI_TEST_CHECK(pitch <= 1.0f && pitch >= -1.0f); // range check
185 int UtcDaliTiltSensorGetRotation(void)
187 AdaptorTestApplication application;
189 tet_infoline("UtcDaliTiltSensorGetRotation");
191 TiltSensor sensor = GetTiltSensor();
192 DALI_TEST_CHECK(sensor);
194 Quaternion rotation = sensor.GetRotation();
196 Radian roll(sensor.GetRoll());
197 Radian pitch(sensor.GetPitch());
199 Quaternion expectedRotation = Quaternion(roll * Math::PI * -0.5f, Vector3::YAXIS) *
200 Quaternion(pitch * Math::PI * -0.5f, Vector3::XAXIS);
202 DALI_TEST_EQUALS(rotation, expectedRotation, ROTATION_EPSILON, TEST_LOCATION);
206 int UtcDaliTiltSensorSignalTilted(void)
208 AdaptorTestApplication application;
210 tet_infoline("UtcDaliTiltSensorSignalTilted");
212 TiltSensor sensor = GetTiltSensor();
213 DALI_TEST_CHECK(sensor);
216 Radian angle(Degree(-45));
217 //Setting a negative threshold for testing purpose
218 sensor.SetRotationThreshold(angle);
223 int UtcDaliTiltSensorSetUpdateFrequency(void)
225 AdaptorTestApplication application;
227 tet_infoline("UtcDaliTiltSensorSetUpdateFrequency");
229 TiltSensor sensor = GetTiltSensor();
230 DALI_TEST_CHECK(sensor);
231 sensor.SetUpdateFrequency(1.0f /*hertz*/);
232 DALI_TEST_EQUALS(sensor.GetUpdateFrequency(), 1.0f, TEST_LOCATION);
234 sensor.SetUpdateFrequency(60.0f /*hertz*/);
235 DALI_TEST_EQUALS(sensor.GetUpdateFrequency(), 60.0f, TEST_LOCATION);
240 int UtcDaliTiltSensorSetRotationThreshold01(void)
242 AdaptorTestApplication application;
244 tet_infoline("UtcDaliTiltSensorSetRotationThreshold01");
246 TiltSensor sensor = GetTiltSensor();
247 DALI_TEST_CHECK(sensor);
250 Radian angle(Degree(-45));
251 sensor.SetRotationThreshold(angle);
252 DALI_TEST_EQUALS(sensor.GetRotationThreshold(), angle, TEST_LOCATION);
255 sensor.SetRotationThreshold(angle);
256 DALI_TEST_EQUALS(sensor.GetRotationThreshold(), angle, TEST_LOCATION);