Fix the issue on AppControl share (BT) operation
[platform/core/connectivity/bluetooth-frwk.git] / test / bluetooth-frwk-test.c
index 643679b..31d934b 100644 (file)
@@ -23,9 +23,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 #include <pthread.h>
-#include <dbus/dbus.h>
+#include <stdint.h>
 
 #include "bluetooth-api.h"
 #include "bluetooth-hid-api.h"
@@ -40,7 +40,7 @@ bluetooth_device_address_t searched_device = { {0} };
 #define DISCOVER_TIMEOUT 20
 #define DISCOVER_CANCEL_INTERVAL 3
 
-#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
+#define PRT(format, args...) printf("%s:() "format, __FUNCTION__, ##args)
 #define TC_PRT(format, args...) PRT(format"\n", ##args)
 
 #define TC_PASS 1
@@ -189,51 +189,13 @@ tc_table_t tc_table[] = {
        {"bluetooth_gatt_unregister_service", 99},
        {"bluetooth_gatt_delete_services", 100},
 
-#if 0
-       {"bluetooth_rfcomm_is_server_uuid_available"    , 26},
-
-       {"bluetooth_hdp_activate"       , 30},
-       {"bluetooth_hdp_deactivate"     , 31},
-       {"bluetooth_hdp_connect"        , 32},
-       {"bluetooth_hdp_disconnect"     , 33},
-       {"bluetooth_hdp_send_data"      , 34},
-
-       {"bluetooth_opc_init"           , 35},
-       {"bluetooth_opc_push_file"      , 36},
-       {"bluetooth_opc_cancel_push"    , 37},
-       {"bluetooth_opc_deinit"         , 38},
-       {"bluetooth_obex_server_init"   , 39},
-       {"bluetooth_obex_server_deinit" , 40},
-       {"bluetooth_obex_server_accept_authorize"       , 41},
-       {"bluetooth_obex_server_reject_authorize"       , 42},
-       {"bluetooth_is_supported"       , 43},
-       {"bluetooth_opc_session_is_exist"       , 46},
-       {"bluetooth_obex_server_is_activated"   , 47},
-       {"bluetooth_obex_server_cancel_transfer"        , 48},
-
-       {"bluetooth_oob_read_local_data"        , 50},
-       {"bluetooth_oob_add_remote_data"        , 51},
-       {"bluetooth_oob_remove_remote_data"     , 52},
-
-       {"bluetooth_network_activate_server"    , 60},
-       {"bluetooth_network_deactivate_server"  , 61},
-       {"bluetooth_network_connect"    , 62},
-       {"bluetooth_network_disconnect" , 63},
-
-       {"bluetooth_gatt_discover_primary_services", 64},
-       {"bluetooth_gatt_discover_service_characteristics",     65},
-       {"bluetooth_gatt_get_service_property",         66},
-       {"bluetooth_gatt_get_characteristics_value",    67},
-       {"bluetooth_gatt_set_characteristics_value",    68},
-#endif
        /* -----------------------------------------*/
        {"Finish"                                                       , 0x00ff},
        {NULL                                                           , 0x0000},
 
 };
 
-#define tc_result(success, tc_index) \
-       TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS) ? "Success" : "Failed"));
+#define tc_result(success, tc_index)
 
 bluetooth_device_info_t bond_dev;
 int is_bond_device = FALSE;
@@ -270,7 +232,14 @@ int test_input_callback(void *data)
        int ret = 0;
        int test_id;
 
+#ifdef ARCH64
+       test_id = find_tc_number((uintptr_t)data);
+#else
        test_id = find_tc_number((int)data);
+#endif
+       if (test_id == -1)
+               return 0;
+
        TC_PRT("TC : %s[%d]", tc_table[test_id].tc_name, tc_table[test_id].tc_code);
 
        switch (tc_table[test_id].tc_code) {
@@ -280,7 +249,7 @@ int test_input_callback(void *data)
                break;
 
        case 1:
-               bluetooth_register_callback(bt_event_callback, NULL);
+               ret = bluetooth_register_callback(bt_event_callback, NULL);
                if (ret < 0) {
                        TC_PRT("%s failed with [0x%04x]", tc_table[0].tc_name, ret);
                        tc_result(TC_FAIL, 1);
@@ -288,7 +257,7 @@ int test_input_callback(void *data)
                break;
 
        case 2:
-               bluetooth_unregister_callback();
+               ret = bluetooth_unregister_callback();
                if (ret < 0) {
                        TC_PRT("%s failed with [0x%04x]", tc_table[1].tc_name, ret);
                        tc_result(TC_FAIL, 1);
@@ -551,7 +520,7 @@ int test_input_callback(void *data)
                ret = bluetooth_authorize_device(&device_address, FALSE);
                if (ret < 0)
                        TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret);
-                       break;
+               break;
        }
        case 25:
        {
@@ -773,6 +742,7 @@ int test_input_callback(void *data)
                TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
 
                if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
+                       BLUETOOTH_BDADDR_BREDR,
                        &g_local_oob_data.oob_data))
                        TC_PRT("ERROR in bluetooth_oob_add_remote_data\n");
                else
@@ -1132,36 +1102,48 @@ int test_input_callback(void *data)
 
        case 92:
        {
+/*
+#if TODO_40
                ret = bluetooth_gatt_init();
                if (ret < 0)
                        TC_PRT("gatt init failed with [0x%04x]", ret);
+#endif
+*/
                break;
        }
 
        case 93:
        {
+/*
+#if TODO_40
                ret = bluetooth_gatt_deinit();
                if (ret < 0)
                        TC_PRT("gatt deinit failed with [0x%04x]", ret);
-
+#endif
+*/
                break;
        }
 
        case 94:
        {
+/*
+#if TODO_40
                char *service_uuid = g_strdup("00001802-0000-1000-8000-00805f9b34fb");
 
                ret = bluetooth_gatt_add_service(service_uuid,
                        &svc_obj_path);
 
                TC_PRT("service obj_path is %s", svc_obj_path);
-
+#endif
+*/
                break;
        }
 
        case 95:
        {
+/* #if TODO_40 */
                /* testing with dummy values*/
+/*
                char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
                bt_gatt_permission_t perms = 0;
                bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
@@ -1174,11 +1156,14 @@ int test_input_callback(void *data)
                        perms, props, &char_obj_path);
 
                TC_PRT("characteristic obj_path is %s", char_obj_path);
-
+#endif
+*/
                break;
        }
 
        case 96: {
+/*
+#if TODO_40
                char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
                bt_gatt_permission_t perms = BLUETOOTH_GATT_PERMISSION_READ |
                                BLUETOOTH_GATT_PERMISSION_WRITE;
@@ -1186,47 +1171,63 @@ int test_input_callback(void *data)
                ret = bluetooth_gatt_add_descriptor(char_obj_path,
                        desc_uuid, perms, &desc_obj_path);
                TC_PRT("add descriptor error is %d", ret);
-
+#endif
+*/
                break;
        }
 
        case 97: {
+/*
+#if TODO_40
                ret = bluetooth_gatt_register_service(svc_obj_path);
                TC_PRT("register service error is %d", ret);
-
+#endif
+*/
                break;
        }
 
        case 98: {
+/*
+#if TODO_40
                ret = bluetooth_gatt_register_application();
 
                TC_PRT("register service error is %d", ret);
-
+#endif
+*/
                break;
        }
 
        case 99: {
+/*
+#if TODO_40
                char char_data[4] = {10, 20, 30, 40};
                int char_length = 4;
                ret = bluetooth_gatt_update_characteristic(char_obj_path,
                                        char_data, char_length);
 
                TC_PRT("update_characteristic error is %d", ret);
-
+#endif
+*/
                break;
        }
 
        case 100: {
+/*
+#if TODO_40
                ret = bluetooth_gatt_unregister_service(svc_obj_path);
                TC_PRT("service removed with error is %d", ret);
-
+#endif
+*/
                break;
        }
 
        case 101:
+/*
+#if TODO_40
                ret = bluetooth_gatt_delete_services();
                TC_PRT("services deleted with error is %d", ret);
-
+#endif
+*/
                break;
 
        default:
@@ -1239,8 +1240,6 @@ void startup()
 {
        TC_PRT("bluetooth framework TC startup");
 
-       dbus_threads_init_default();
-
        main_loop = g_main_loop_new(NULL, FALSE);
 }
 
@@ -1381,25 +1380,6 @@ void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_dat
        {
                // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
                // 2011.01.06
-#if 0
-//             int i = 0;
-               TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
-               if (param->result >= BLUETOOTH_ERROR_NONE) {
-                       ///tc_result(TC_PASS, 15);
-                       bluetooth_device_info_t * bt_dev_info = (bluetooth_device_info_t*)param->param_data;
-                               TC_PRT("Dev Name = %s, Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X, COD (major,minor,service)= 0x%x:%x:%x\n", bt_dev_info->device_name.name,
-                               bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
-                               bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
-                               bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
-
-               } else if (param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/ {
-                       tc_result(TC_PASS, 15);
-                       TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
-               } else {
-                       tc_result(TC_FAIL, 15);
-                       TC_PRT("*****API failed ***** ");
-               }
-#endif
                break;
        }
 
@@ -1583,100 +1563,6 @@ void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_dat
        {       TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
                break;
        }
-#if 0
-       case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
-       {
-               TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
-               bt_gatt_handle_info_t *prim_svc = param->param_data;
-               int i;
-
-               if (prim_svc == NULL) {
-                       TC_PRT("prim_svc is NULL");
-                       break;
-               }
-
-               for (i = 0; i < prim_svc->count; i++)
-                       TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
-
-               break;
-       }
-
-       case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
-       {
-               TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
-               bt_gatt_discovered_char_t *svc_char = param->param_data;
-               int i = 0;
-
-               if (svc_char == NULL) {
-                       TC_PRT("svc_char is NULL");
-                       break;
-               }
-
-               if (svc_char->service_handle != NULL)
-                       TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
-
-               for (i = 0; i < svc_char->handle_info.count; i++)
-                       TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
-
-               break;
-       }
-
-       case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
-       {
-               TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
-               bt_gatt_service_property_t *svc_pty = param->param_data;
-               int i;
-
-               if (svc_pty == NULL) {
-                       TC_PRT("char_pty is NULL \n");
-                       break;
-               }
-
-               if (svc_pty->service_handle != NULL)
-                       TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
-
-               if (svc_pty->uuid != NULL)
-                       TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
-
-               for (i = 0; i < svc_pty->handle_info.count; i++)
-                       TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
-
-               break;
-       }
-
-       case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
-       {
-               TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
-               bt_gatt_char_property_t *char_pty = param->param_data;
-               int i = 0;
-
-               if (char_pty->char_handle != NULL)
-                       TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
-
-               if (char_pty->uuid != NULL)
-                       TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
-
-               if (char_pty == NULL) {
-                       TC_PRT("char_pty is NULL \n");
-                       break;
-               }
-
-               if (char_pty->name != NULL)
-                       TC_PRT("char_pty->name %s \n", char_pty->name);
-
-               if (char_pty->description != NULL)
-                       TC_PRT("char_pty->description %s \n", char_pty->description);
-
-               if (char_pty->val != NULL) {
-                       TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
-
-                       for (i = 0; i < char_pty->val_len; i++)
-                               TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
-               }
-
-               break;
-       }
-#endif
        case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
        {
                bluetooth_authentication_request_info_t *auth_info = param->param_data;
@@ -1745,9 +1631,13 @@ void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_dat
 
 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
 {
-       char buf[10] = {0};
+       char buf[49] = {0};
 
+#ifdef ARCH64
+       unsigned long len = 0;
+#else
        unsigned int len = 0;
+#endif
        int test_id;
        memset(buf, 0, sizeof(buf));
 
@@ -1762,8 +1652,11 @@ static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer dat
 
        test_id = atoi(buf);
 
-       if (test_id)
-               g_idle_add(test_input_callback, (void*)test_id);
+#ifdef ARCH64
+       g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
+#else
+       g_idle_add(test_input_callback, (void *)test_id);
+#endif
 
        return TRUE;
 }