sensorctl: clean up testcases
[platform/core/system/sensord.git] / src / sensorctl / testcase / sensor_interval.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <unistd.h>
21 #include <sensor_internal.h>
22
23 #include "log.h"
24 #include "mainloop.h"
25 #include "test_bench.h"
26 #include "sensor_adapter.h"
27
28 static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
29 {
30         EXPECT_GT(data->timestamp, 0);
31         mainloop::stop();
32 }
33
34 TESTCASE(interval_test, 20ms_p)
35 {
36         int err, count, handle;
37         bool ret;
38         sensor_t *sensors;
39         sensor_type_t type;
40
41         err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count);
42         ASSERT_EQ(err, 0);
43
44         for (int i = 0; i < count; ++i) {
45                 sensord_get_type(sensors[i], &type);
46                 sensor_info info(type, 0, 20, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL);
47
48                 ret = sensor_adapter::start(info, handle);
49                 EXPECT_TRUE(ret);
50
51                 mainloop::run();
52
53                 ret = sensor_adapter::stop(info, handle);
54                 EXPECT_TRUE(ret);
55         }
56
57         free(sensors);
58
59         return true;
60 }
61
62 TESTCASE(interval_test, 100ms_p)
63 {
64         int err, count, handle;
65         bool ret;
66         sensor_t *sensors;
67         sensor_type_t type;
68
69         err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count);
70         ASSERT_EQ(err, 0);
71
72         for (int i = 0; i < count; ++i) {
73                 sensord_get_type(sensors[i], &type);
74                 sensor_info info(type, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL);
75
76                 ret = sensor_adapter::start(info, handle);
77                 EXPECT_TRUE(ret);
78
79                 mainloop::run();
80
81                 ret = sensor_adapter::stop(info, handle);
82                 EXPECT_TRUE(ret);
83         }
84
85         free(sensors);
86
87         return true;
88 }
89
90 TESTCASE(interval_test, 200ms_p)
91 {
92         int err, count, handle;
93         bool ret;
94         sensor_t *sensors;
95         sensor_type_t type;
96
97         err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count);
98         ASSERT_EQ(err, 0);
99
100         for (int i = 0; i < count; ++i) {
101                 sensord_get_type(sensors[i], &type);
102                 sensor_info info(type, 0, 200, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL);
103
104                 ret = sensor_adapter::start(info, handle);
105                 EXPECT_TRUE(ret);
106
107                 mainloop::run();
108
109                 ret = sensor_adapter::stop(info, handle);
110                 EXPECT_TRUE(ret);
111         }
112
113         free(sensors);
114
115         return true;
116 }