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(unsigned int event_type, sensor_event_data_t *event, 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) {
124 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_sensor_list\n", sensor_type, event_type);
128 result = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL);
131 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type);
135 result_boolean = sensord_start(handle, 1);
137 if (!result_boolean) {
138 sensord_unregister_event(handle, event_type);
139 sensord_disconnect(handle);
140 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_start\n", sensor_type, event_type);
145 result_boolean = sensord_get_data(handle, event_type, &data);
146 if (!result_boolean) {
147 sensord_unregister_event(handle, event_type);
148 sensord_disconnect(handle);
149 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_data\n", sensor_type, event_type);
153 g_main_loop_run(mainloop);
154 g_main_loop_unref(mainloop);
156 result_boolean = sensord_change_event_interval(handle, event_type, 101);
157 if (!result_boolean) {
158 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_event_interval\n", sensor_type, event_type);
162 result_boolean = sensord_set_option(handle, SENSOR_OPTION_ON_IN_SCREEN_OFF);
163 if (!result_boolean){
164 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_sensor_option\n", sensor_type, event_type);
168 result_boolean = sensord_unregister_event(handle, event_type);
170 if (!result_boolean) {
171 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_unregister_event\n", sensor_type, event_type);
175 result_boolean = sensord_stop(handle);
177 if (!result_boolean) {
178 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_stop\n", sensor_type, event_type);
182 result_boolean = sensord_disconnect(handle);
184 if (!result_boolean) {
185 fprintf(fp, "Sensor - %d, event - %d, failed at sensord_disconnect\n", sensor_type, event_type);
192 int main(int argc, char **argv)
196 int interval = DEFAULT_EVENT_INTERVAL;
198 interval = atof(argv[1]);
200 fp = fopen("auto_test.output", "w+");
202 result = check_sensor_api(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
203 fprintf(fp, "Accelerometer - RAW_DATA_REPORT_ON_TIME - %d\n", result);
205 result = check_sensor_api(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
206 fprintf(fp, "Geomagnetic - RAW_DATA_REPORT_ON_TIME - %d\n", result);
208 result = check_sensor_api(GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
209 fprintf(fp, "Gravity - RAW_DATA_REPORT_ON_TIME - %d\n", result);
211 result = check_sensor_api(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
212 fprintf(fp, "Gyroscope - RAW_DATA_REPORT_ON_TIME - %d\n", result);
214 result = check_sensor_api(LIGHT_EVENT_LUX_DATA_REPORT_ON_TIME, interval);
215 fprintf(fp, "Light - RAW_DATA_REPORT_ON_TIME - %d\n", result);
217 result = check_sensor_api(LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
218 fprintf(fp, "Linear Accel - RAW_DATA_REPORT_ON_TIME - %d\n", result);
220 result = check_sensor_api(ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
221 fprintf(fp, "Orientation - RAW_DATA_REPORT_ON_TIME - %d\n", result);
223 result = check_sensor_api(PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
224 fprintf(fp, "Pressure - RAW_DATA_REPORT_ON_TIME - %d\n", result);
226 result = check_sensor_api(ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
227 fprintf(fp, "Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result);
229 result = check_sensor_api(TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME, interval);
230 fprintf(fp, "Temperature - RAW_DATA_REPORT_ON_TIME - %d\n", result);
232 printf("Logs printed in ./auto_test.output\n");