Fix issue where key input did not work properly in 64bit environment 03/323003/1
authorWootak Jung <wootak.jung@samsung.com>
Mon, 21 Apr 2025 09:46:40 +0000 (18:46 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Mon, 21 Apr 2025 09:48:59 +0000 (18:48 +0900)
Change-Id: I3fd0f9f5d7d85aa431238109b664877cd49ac14c

tests/test/bt_unit_test.c

index a27ca1972603ff94b16e655b06de349d6725703a..8b42f244edb8b11290285d2b74c67947d4418904 100644 (file)
@@ -27,9 +27,7 @@
 #include <unistd.h>
 #include <glib.h>
 #include <ctype.h>
-#ifdef ARCH64
 #include <stdint.h>
-#endif
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <net/if.h>
@@ -2890,11 +2888,7 @@ bool __bt_gatt_client_foreach_chr_cb(int total,
 bool __bt_gatt_client_foreach_svc_cb(int total,
        int index, bt_gatt_h svc_handle, void *data)
 {
-#ifdef ARCH64
-       int test_id = (int)(uintptr_t) data;
-#else
-       int test_id = (int)data;
-#endif
+       int test_id = GPOINTER_TO_INT(data);
        int ret;
        char *uuid = NULL;
        char *str = NULL;
@@ -2910,13 +2904,8 @@ bool __bt_gatt_client_foreach_svc_cb(int total,
        g_free(uuid);
 
        if (test_id == BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL) {
-#ifdef ARCH64
                ret = bt_gatt_service_foreach_characteristics(svc_handle,
-                               __bt_gatt_client_foreach_chr_cb, (void *)(uintptr_t)test_id);
-#else
-               ret = bt_gatt_service_foreach_characteristics(svc_handle,
-                               __bt_gatt_client_foreach_chr_cb, (void *)test_id);
-#endif
+                               __bt_gatt_client_foreach_chr_cb, GINT_TO_POINTER(test_id));
                if (ret != BT_ERROR_NONE)
                        TC_PRT("bt_gatt_service_foreach_characteristics is failed : %d", ret);
        }
@@ -2927,11 +2916,7 @@ bool __bt_gatt_client_foreach_svc_cb(int total,
 bool __bt_hps_client_svc_cb(int total,
        int index, bt_gatt_h svc_handle, void *data)
 {
-#ifdef ARCH64
-       int test_id = (int) (uintptr_t) data;
-#else
-       int test_id = (int)data;
-#endif
+       int test_id = GPOINTER_TO_INT(data);
        int ret;
        char *uuid = NULL;
        char *str = NULL;
@@ -2946,15 +2931,9 @@ bool __bt_hps_client_svc_cb(int total,
                        str ? str : "Unknown", uuid);
 
                if (test_id == BT_UNIT_TEST_FUNCTION_HPS_CLIENT_PRINT_ALL) {
-#ifdef ARCH64
-                       ret = bt_gatt_service_foreach_characteristics(svc_handle,
-                                       __bt_gatt_client_foreach_chr_cb,
-                                       (void *)(uintptr_t)test_id);
-#else
                        ret = bt_gatt_service_foreach_characteristics(svc_handle,
                                        __bt_gatt_client_foreach_chr_cb,
-                                       (void *)test_id);
-#endif
+                                       GINT_TO_POINTER(test_id));
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("bt_gatt_service_foreach_characteristics is failed : %d", ret);
                }
@@ -4549,11 +4528,7 @@ done:
 
                if (param_index  == g_test_param.param_count) {
                        need_to_set_params = false;
-#ifdef ARCH64
-                       test_input_callback((void *)(uintptr_t)test_id);
-#else
-                       test_input_callback((void *)test_id);
-#endif
+                       test_input_callback(GINT_TO_POINTER(test_id));
                        param_index = 0;
                        return 0;
                }
@@ -4567,11 +4542,7 @@ done:
 int test_input_callback(void *data)
 {
        int ret = 0;
-#ifdef ARCH64
-       int test_id = (uintptr_t)data;
-#else
-       int test_id = (int)data;
-#endif
+       int test_id = GPOINTER_TO_INT(data);
 
        switch (current_tc_table) {
        case BT_UNIT_TEST_TABLE_MAIN: {
@@ -7279,15 +7250,9 @@ int test_input_callback(void *data)
                        break;
                }
                case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL: {
-#ifdef ARCH64
-                       ret = bt_gatt_client_foreach_services(client,
-                               __bt_gatt_client_foreach_svc_cb,
-                               (void *)(uintptr_t)test_id);
-#else
                        ret = bt_gatt_client_foreach_services(client,
                                __bt_gatt_client_foreach_svc_cb,
-                               (void *)test_id);
-#endif
+                               GINT_TO_POINTER(test_id));
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
@@ -7493,13 +7458,8 @@ int test_input_callback(void *data)
                        break;
                }
                case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES: {
-#ifdef ARCH64
                        ret = bt_gatt_client_foreach_services(client,
-                               __bt_gatt_client_foreach_svc_cb, (void *)(uintptr_t)test_id);
-#else
-                       ret = bt_gatt_client_foreach_services(client,
-                               __bt_gatt_client_foreach_svc_cb, (void *)(uintptr_t)test_id);
-#endif
+                               __bt_gatt_client_foreach_svc_cb, GINT_TO_POINTER(test_id));
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("bt_gatt_client_foreach_services_by_uuid is failed");
                        break;
@@ -8194,13 +8154,8 @@ int test_input_callback(void *data)
                        break;
                }
                case BT_UNIT_TEST_FUNCTION_GATT_SERVER_FOREACH_SERVICES: {
-#ifdef ARCH64
-                       ret = bt_gatt_server_foreach_services(server,
-                       __bt_gatt_server_foreach_svc_cb, (void *)(uintptr_t)test_id);
-#else
                        ret = bt_gatt_server_foreach_services(server,
-                       __bt_gatt_server_foreach_svc_cb, (void *)test_id);
-#endif
+                       __bt_gatt_server_foreach_svc_cb, GINT_TO_POINTER(test_id));
                        TC_PRT("bt_gatt_server_foreach_services: %s\n", __bt_get_error_message(ret));
                        break;
                }
@@ -8419,13 +8374,8 @@ int test_input_callback(void *data)
                        break;
                }
                case BT_UNIT_TEST_FUNCTION_HPS_CLIENT_PRINT_ALL: {
-#ifdef ARCH64
-                       ret = bt_gatt_client_foreach_services(hps_client,
-                                       __bt_hps_client_svc_cb, (void *)(uintptr_t)test_id);
-#else
                        ret = bt_gatt_client_foreach_services(hps_client,
-                                       __bt_hps_client_svc_cb, (void *)test_id);
-#endif
+                                       __bt_hps_client_svc_cb, GINT_TO_POINTER(test_id));
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
@@ -11401,12 +11351,7 @@ static gboolean key_event_cb(GIOChannel *chan,
                                gpointer data)
 {
        char buf[BUFFER_LEN] = { 0 };
-
-#ifdef ARCH64
-               unsigned long len = 0;
-#else
-               unsigned int len = 0;
-#endif
+       gsize len = 0;
        int test_id;
        bool is_call_api = false;
 
@@ -11459,12 +11404,9 @@ static gboolean key_event_cb(GIOChannel *chan,
                        && is_call_api == true) {
                memcpy(remote_addr, buf, 17);
                remote_addr[17] = 0;
-       } else if (test_id && is_call_api)
-#ifdef ARCH64
-               g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
-#else
-               g_idle_add(test_input_callback, (void *)test_id);
-#endif
+       } else if (test_id && is_call_api) {
+               g_idle_add(test_input_callback, GINT_TO_POINTER(test_id));
+       }
        return TRUE;
 }