4 * Copyright (c) 2017 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.
20 #include <sensor_internal.h>
24 #include "test_bench.h"
25 #include "sensor_adapter.h"
27 static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
29 EXPECT_GT(data->timestamp, 0);
30 EXPECT_NEAR(data->values[0], 0, 19.6);
31 EXPECT_NEAR(data->values[1], 0, 19.6);
32 EXPECT_NEAR(data->values[2], 0, 19.6);
37 TESTCASE(accelerometer_basic, start_stop_p)
42 sensor_info info(ACCELEROMETER_SENSOR, 0,
43 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL);
45 ret = sensor_adapter::start(info, handle);
50 ret = sensor_adapter::stop(info, handle);
56 static void get_data_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
61 TESTCASE(accelerometer_basic, get_data_p)
67 sensor_info info(ACCELEROMETER_SENSOR, 0,
68 100, 1000, SENSOR_OPTION_ALWAYS_ON, get_data_cb, NULL);
70 ret = sensor_adapter::start(info, handle);
75 ret = sensor_adapter::get_data(handle, info.type, data);
78 ret = sensor_adapter::stop(info, handle);
84 static unsigned long long prev_prev_ts;
85 static unsigned long long prev_ts;
86 static int event_count;
88 static void accel_regular_interval_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
92 if (prev_prev_ts == 0) {
93 prev_prev_ts = data->timestamp;
98 prev_ts = data->timestamp;
102 prev_gap = prev_ts - prev_prev_ts;
103 current_gap = data->timestamp - prev_ts;
105 EXPECT_NEAR(current_gap, prev_gap, 10000);
106 prev_prev_ts = prev_ts;
107 prev_ts = data->timestamp;
109 if (event_count++ > 3)
113 TESTCASE(accelerometer_interval, regular_interval_p)
121 sensor_info info(ACCELEROMETER_SENSOR, 0,
122 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_regular_interval_cb, NULL);
124 ret = sensor_adapter::start(info, handle);
129 ret = sensor_adapter::stop(info, handle);
135 static void accel_interval_100ms_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
138 prev_ts = data->timestamp;
142 /* 100ms + 20ms(error) */
143 EXPECT_LE(data->timestamp - prev_ts, 120000);
144 prev_ts = data->timestamp;
146 if (event_count++ > 3)
150 TESTCASE(accelerometer_interval, 100ms_interval_p)
158 sensor_info info(ACCELEROMETER_SENSOR, 0,
159 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_interval_100ms_cb, NULL);
161 ret = sensor_adapter::start(info, handle);
166 ret = sensor_adapter::stop(info, handle);