4 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sensor_internal.h>
24 #include <sensor_common.h>
26 #include <sensor_common.h>
29 #define DEFAULT_EVENT_INTERVAL 100
31 static GMainLoop *mainloop;
34 void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
36 g_main_loop_quit(mainloop);
39 bool check_sensor_api(unsigned int event_type, int cond_value)
43 mainloop = g_main_loop_new(NULL, FALSE);
45 sensor_type_t sensor_type = event_type >> 16;
46 sensor_t sensor = sensord_get_sensor(sensor_type);
48 handle = sensord_connect(sensor);
51 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_connect\n", sensor_type, event_type);
56 bool result_boolean = sensord_is_supported_event_type(sensor, event_type, &is_supported);
57 if (!result_boolean && !is_supported) {
58 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_is_supported_event\n", sensor_type, event_type);
63 result_boolean = sensord_get_min_interval(sensor, &output);
64 if (!result_boolean) {
65 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_interval\n", sensor_type, event_type);
70 result_boolean = sensord_get_resolution(sensor, &output3);
71 if (!result_boolean) {
72 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_resolution\n", sensor_type, event_type);
76 result_boolean = sensord_get_max_range(sensor, &output3);
77 if (!result_boolean) {
78 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_max_range\n", sensor_type, event_type);
82 result_boolean = sensord_get_min_range(sensor, &output3);
83 if (!result_boolean) {
84 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_range\n", sensor_type, event_type);
88 sensor_privilege_t output4;
89 result_boolean = sensord_get_privilege(sensor, &output4);
90 if (!result_boolean) {
91 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_privilege\n", sensor_type, event_type);
95 const char* result_char = sensord_get_vendor(sensor);
97 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_vendor\n", sensor_type, event_type);
101 result_char = sensord_get_name(sensor);
103 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_name\n", sensor_type, event_type);
107 sensor_type_t output_type;
108 result_boolean = sensord_get_type(sensor, &output_type);
109 if (!result_boolean) {
110 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_type\n", sensor_type, event_type);
114 unsigned int *output2;
115 result_boolean = sensord_get_supported_event_types(sensor, &output2, &output);
116 if (!result_boolean) {
117 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_supported_event_types\n", sensor_type, event_type);
121 sensor_t *output_list;
122 result_boolean = sensord_get_sensor_list(sensor_type, &output_list, &output);
123 if (!result_boolean) {
125 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_sensor_list\n", sensor_type, event_type);
129 result_boolean = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL);
130 if (!result_boolean) {
133 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type);
137 result_boolean = sensord_start(handle, 1);
138 if (!result_boolean) {
139 sensord_unregister_event(handle, event_type);
140 sensord_disconnect(handle);
143 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_start\n", sensor_type, event_type);
148 result_boolean = sensord_get_data(handle, event_type, &data);
149 if (!result_boolean) {
150 sensord_unregister_event(handle, event_type);
151 sensord_disconnect(handle);
154 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_data\n", sensor_type, event_type);
158 g_main_loop_run(mainloop);
159 g_main_loop_unref(mainloop);
161 result_boolean = sensord_change_event_interval(handle, event_type, 101);
162 if (!result_boolean) {
165 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_event_interval\n", sensor_type, event_type);
169 result_boolean = sensord_set_option(handle, SENSOR_OPTION_ON_IN_SCREEN_OFF);
170 if (!result_boolean){
173 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_sensor_option\n", sensor_type, event_type);
177 result_boolean = sensord_unregister_event(handle, event_type);
178 if (!result_boolean) {
181 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_unregister_event\n", sensor_type, event_type);
185 result_boolean = sensord_stop(handle);
186 if (!result_boolean) {
189 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_stop\n", sensor_type, event_type);
193 result_boolean = sensord_disconnect(handle);
194 if (!result_boolean) {
197 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_disconnect\n", sensor_type, event_type);
207 int main(int argc, char **argv)
211 int interval = DEFAULT_EVENT_INTERVAL;
213 interval = atof(argv[1]);
215 fp = fopen("auto_test.output", "w+");
217 result = check_sensor_api(ACCELEROMETER_RAW_DATA_EVENT, interval);
218 fprintf(fp, "Accelerometer - RAW_DATA_REPORT_ON_TIME - %d\n", result);
220 result = check_sensor_api(GEOMAGNETIC_RAW_DATA_EVENT, interval);
221 fprintf(fp, "Geomagnetic - RAW_DATA_REPORT_ON_TIME - %d\n", result);
223 result = check_sensor_api(GRAVITY_RAW_DATA_EVENT, interval);
224 fprintf(fp, "Gravity - RAW_DATA_REPORT_ON_TIME - %d\n", result);
226 result = check_sensor_api(GYROSCOPE_RAW_DATA_EVENT, interval);
227 fprintf(fp, "Gyroscope - RAW_DATA_REPORT_ON_TIME - %d\n", result);
229 result = check_sensor_api(LIGHT_LUX_DATA_EVENT, interval);
230 fprintf(fp, "Light - RAW_DATA_REPORT_ON_TIME - %d\n", result);
232 result = check_sensor_api(LINEAR_ACCEL_RAW_DATA_EVENT, interval);
233 fprintf(fp, "Linear Accel - RAW_DATA_REPORT_ON_TIME - %d\n", result);
235 result = check_sensor_api(ORIENTATION_RAW_DATA_EVENT, interval);
236 fprintf(fp, "Orientation - RAW_DATA_REPORT_ON_TIME - %d\n", result);
238 result = check_sensor_api(TILT_RAW_DATA_EVENT, interval);
239 fprintf(fp, "Tilt - RAW_DATA_REPORT_ON_TIME - %d\n", result);
241 result = check_sensor_api(PRESSURE_RAW_DATA_EVENT, interval);
242 fprintf(fp, "Pressure - RAW_DATA_REPORT_ON_TIME - %d\n", result);
244 result = check_sensor_api(ROTATION_VECTOR_RAW_DATA_EVENT, interval);
245 fprintf(fp, "Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result);
247 result = check_sensor_api(GEOMAGNETIC_RV_RAW_DATA_EVENT, interval);
248 fprintf(fp, "Geomagnetic Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result);
250 result = check_sensor_api(GAMING_RV_RAW_DATA_EVENT, interval);
251 fprintf(fp, "Gaming Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result);
253 result = check_sensor_api(GYROSCOPE_UNCAL_SENSOR, interval);
254 fprintf(fp, "Gyroscope Uncal Sensor - RAW_DATA_REPORT_ON_TIME - %d\n", result);
256 result = check_sensor_api(TEMPERATURE_RAW_DATA_EVENT, interval);
257 fprintf(fp, "Temperature - RAW_DATA_REPORT_ON_TIME - %d\n", result);
259 result = check_sensor_api(ULTRAVIOLET_RAW_DATA_EVENT, interval);
260 fprintf(fp, "ULTRAVIOLET - RAW_DATA_REPORT_ON_TIME - %d\n", result);
262 result = check_sensor_api(BIO_LED_RED_RAW_DATA_EVENT, interval);
263 fprintf(fp, "BIO_LED_RED - RAW_DATA_REPORT_ON_TIME - %d\n", result);
265 printf("Logs printed in ./auto_test.output\n");