Prevent a corner case and add static keywords 73/260673/1 accepted/tizen/unified/20210727.124557 submit/tizen/20210726.050348
authortaemin.yeom <taemin.yeom@samsung.com>
Thu, 1 Jul 2021 02:00:28 +0000 (11:00 +0900)
committertaemin.yeom <taemin.yeom@samsung.com>
Thu, 1 Jul 2021 02:17:55 +0000 (11:17 +0900)
Change-Id: I3a5652879b446aa03e09ab935b065411d82f3fa0
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
test/main.c

index ca498c8..97683ab 100644 (file)
@@ -5,7 +5,7 @@
 #include <glib.h>
 #include <sensor.h>
 
-const sensor_type_e sensor_type[] =
+static const sensor_type_e sensor_type[] =
 {
        SENSOR_ACCELEROMETER,
        SENSOR_GRAVITY,
@@ -36,7 +36,7 @@ const sensor_type_e sensor_type[] =
        SENSOR_HUMAN_SLEEP_DETECTOR
 };
 
-const char *sensor_name[] = {
+static const char *sensor_name[] = {
        "Accelerometer",
        "Gravity sensor",
        "Linear acceleration sensor",
@@ -67,18 +67,18 @@ const char *sensor_name[] = {
 };
 
 // the number of value to be verified of the sensor
-const int value_num[] = {3, 3, 3, 3, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 4, 4, 1, 1, 1, 3, 1};
-
-GMainLoop *loop;
-bool turned_on[SENSOR_NUM];
-int min_range[SENSOR_NUM];
-int max_range[SENSOR_NUM];
-int called_num[SENSOR_NUM];
-int miss[SENSOR_NUM];
-int callback_count;
-bool running;
-
-void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data)
+static const int value_num[] = {3, 3, 3, 3, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 4, 4, 1, 1, 1, 3, 1};
+
+static GMainLoop *loop;
+static bool turned_on[SENSOR_NUM];
+static int min_range[SENSOR_NUM];
+static int max_range[SENSOR_NUM];
+static int called_num[SENSOR_NUM];
+static int miss[SENSOR_NUM];
+static int callback_count;
+static bool running;
+
+static void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data)
 {
        const char *name;
        sensor_type_e type;
@@ -139,7 +139,7 @@ void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count,
        }
 }
 
-int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener)
+static int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener)
 {
        bool supported;
        int ret;
@@ -183,16 +183,24 @@ int main()
 
        sensor_h sensor[29];
        sensor_listener_h listener[29];
+       int usable = 0;
 
        for (int i = 0; i < SENSOR_NUM; ++i) {
                called_num[i] = 0;
                miss[i] = 0;
-               if (create_sensor_listener(i, &sensor[i], &listener[i]))
+               if (create_sensor_listener(i, &sensor[i], &listener[i])) {
                        turned_on[i] = false;
-               else
+               }
+               else {
                        turned_on[i] = true;
+                       ++usable;
+               }
        }
 
+       if (usable == 0) {
+               g_print("There is no supported sensor.\n");
+               return -1;
+       }
 
        g_print("testing... ");