Merge "Remove DEPRECATED connection_set_ethernet_cable_state_chaged_cb() call" into...
[platform/core/api/connection.git] / test / connection_test.c
index 753cab1..7236b33 100755 (executable)
@@ -92,6 +92,14 @@ static const char *test_print_state(connection_profile_state_e state)
        }
 }
 
+static const char *test_print_internet_state(connection_internet_state_e state)
+{
+       if (state == CONNECTION_INTERNET_STATE_ONLINE)
+               return "Online";
+
+       return "Offline";
+}
+
 static const char *test_print_connection_type(connection_type_e type)
 {
        switch (type) {
@@ -231,6 +239,10 @@ static const char *test_print_error(connection_error_e error)
                return "CONNECTION_ERROR_PERMISSION_DENIED";
        case CONNECTION_ERROR_NOT_SUPPORTED:
                return "CONNECTION_ERROR_NOT_SUPPORTED";
+       case CONNECTION_ERROR_NOT_INITIALIZED:
+               return "CONNECTION_ERROR_NOT_INITIALIZED";
+       case CONNECTION_ERROR_ALREADY_INITIALIZED:
+               return "CONNECTION_ERROR_ALREADY_INITIALIZED";
        default:
                return "CONNECTION_ERROR_UNKNOWN";
        }
@@ -253,6 +265,11 @@ static void test_proxy_changed_callback(const char* ipv4_address, const char* ip
                        ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
 }
 
+static void test_internet_state_changed_callback(connection_internet_state_e state, void* user_data)
+{
+       printf("Internet state changed callback, state : %d\n", state);
+}
+
 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
 {
        char *profile_name;
@@ -854,6 +871,50 @@ static void test_print_wifi_info(connection_profile_h profile)
                printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
 }
 
+static void test_print_mesh_info(connection_profile_h profile)
+{
+       char *essid = NULL;
+       char *bssid = NULL;
+       int rssi = 0;
+       int frequency = 0;
+       connection_wifi_security_type_e security_type;
+       bool pass_required = false;
+
+       if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh essid!\n");
+       else {
+               printf("Mesh essid : %s\n", essid);
+               g_free(essid);
+       }
+
+       if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh bssid!\n");
+       else {
+               printf("Mesh bssid : %s\n", bssid);
+               g_free(bssid);
+       }
+
+       if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh rssi!\n");
+       else
+               printf("Mesh rssi : %d\n", rssi);
+
+       if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh frequency!\n");
+       else
+               printf("Mesh frequency : %d\n", frequency);
+
+       if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh security type!\n");
+       else
+               printf("Mesh security type : %d\n", security_type);
+
+       if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh passphrase required!\n");
+       else
+               printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
+}
+
 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
 {
        char *interface_name = NULL;
@@ -984,8 +1045,9 @@ int test_register_client(void)
                connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
                connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
                connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
-               connection_set_ethernet_cable_state_chaged_cb(connection,
+               connection_set_ethernet_cable_state_changed_cb(connection,
                                        test_get_ethernet_cable_state_callback, NULL);
+               connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
        } else {
                printf("Client registration failed [%s]\n", test_print_error(err));
                return -1;
@@ -1029,6 +1091,65 @@ int  test_deregister_client(void)
        return 1;
 }
 
+int test_register_client_cs(void)
+{
+       int tid = 0;
+       test_get_user_int("Input a TID in C# API :", &tid);
+
+       int err = connection_create_cs(tid, &connection);
+
+       if (CONNECTION_ERROR_NONE == err) {
+               connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
+               connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
+               connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
+               connection_set_ethernet_cable_state_changed_cb(connection,
+                                       test_get_ethernet_cable_state_callback, NULL);
+       } else {
+               printf("Client registration failed [%s]\n", test_print_error(err));
+               return -1;
+       }
+
+       printf("Client registration success\n");
+       return 1;
+}
+
+int  test_deregister_client_cs(void)
+{
+       int rv = 0;
+       GSList *list;
+       connection_profile_h profile;
+       int tid = 0;
+
+       test_get_user_int("Input a TID in C# API :", &tid);
+
+       if (connection != NULL)
+               rv = connection_destroy_cs(tid, connection);
+       else {
+               printf("Cannot deregister : Handle is NULL\n");
+               rv = CONNECTION_ERROR_INVALID_OPERATION;
+       }
+
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Client deregistration fail [%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       if (state_cb_list) {
+               for (list = state_cb_list; list; list = list->next) {
+                       profile = list->data;
+                       connection_profile_destroy(profile);
+               }
+
+               g_slist_free(state_cb_list);
+               state_cb_list = NULL;
+       }
+
+       connection = NULL;
+       printf("Client deregistration success\n");
+
+       return 1;
+}
+
 int test_get_network_state(void)
 {
        int rv = 0;
@@ -1492,12 +1613,20 @@ int test_update_profile(void)
        case CONNECTION_PROFILE_TYPE_ETHERNET:
                if (test_update_network_info(profile) == -1)
                        return -1;
-               break;
 
+               break;
        case CONNECTION_PROFILE_TYPE_BT:
                printf("Not supported!\n");
                /* fall through */
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               if (test_update_wifi_info(profile) == -1)
+                                       return -1;
+                               break;
+                       }
+               }
                return -1;
        }
 
@@ -1513,6 +1642,7 @@ int test_get_profile_info(void)
        connection_profile_type_e prof_type;
        connection_profile_state_e profile_state;
        connection_profile_state_e profile_ipv6_state;
+       connection_internet_state_e internet_state;
        connection_profile_h profile;
        char *profile_name = NULL;
        int address_family = 0;
@@ -1541,6 +1671,11 @@ int test_get_profile_info(void)
        } else
                printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
 
+       if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
+               printf("Fail to get Internet state\n");
+               return -1;
+       } else
+               printf("Internet State : %s\n", test_print_internet_state(internet_state));
 
        if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
                return -1;
@@ -1563,6 +1698,14 @@ int test_get_profile_info(void)
                printf("Profile Type : Bluetooth\n");
                break;
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               printf("Profile Type : Mesh\n");
+                               test_print_mesh_info(profile);
+                               break;
+                       }
+               }
                return -1;
        }
 
@@ -1622,6 +1765,14 @@ int test_refresh_profile_info(void)
                printf("Profile Type : Bluetooth\n");
                break;
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               printf("Profile Type : Mesh\n");
+                               test_print_mesh_info(profile);
+                               break;
+                       }
+               }
                return -1;
        }
 
@@ -2183,6 +2334,141 @@ int test_get_tcpdump_state(void)
        return 1;
 }
 
+int test_mptcp_enable(void)
+{
+       int rv = 0;
+       bool supported = false;
+       rv = connection_mptcp_is_supported(connection, &supported);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+       printf("MPTCP Support: %d\n", supported);
+
+       rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+       return 1;
+}
+
+int test_mptcp_disable(void)
+{
+       int rv = 0;
+       rv = connection_mptcp_disable(connection);
+
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+       return 1;
+}
+
+int test_mptcp_set_path_manager(void)
+{
+       int rv = 0;
+       int input = 0;
+       rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
+
+       switch (input) {
+       case 1:
+               rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
+               break;
+       case 2:
+               rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
+               break;
+       default:
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       return 1;
+}
+
+int test_mptcp_get_path_manager(void)
+{
+       int rv = 0;
+       connection_mptcp_path_manager_e pm;
+
+       rv = connection_mptcp_get_path_manager(connection, &pm);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       switch (pm) {
+       case CONNECTION_MPTCP_PM_DEFAULT:
+               printf("Path Manager: Default\n");
+               break;
+       case CONNECTION_MPTCP_PM_FULLMESH:
+               printf("Path Manager: FullMesh\n");
+               break;
+       default:
+               printf("Error: Invalid Path Manager\n");
+               return -1;
+       }
+
+       return 1;
+}
+
+int test_mptcp_set_scheduler(void)
+{
+       int rv = 0;
+       int input = 0;
+       rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
+
+       switch (input) {
+       case 1:
+               rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
+               break;
+       case 2:
+               rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
+               break;
+       default:
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       return 1;
+}
+
+int test_mptcp_get_scheduler(void)
+{
+       int rv = 0;
+       connection_mptcp_scheduler_e scheduler;
+
+       rv = connection_mptcp_get_scheduler(connection, &scheduler);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Failure[%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       switch (scheduler) {
+       case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
+               printf("Scheduler: Default\n");
+               break;
+       case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
+               printf("Scheduler: RountRobin\n");
+               break;
+       default:
+               printf("Error: Invalid Scheduler\n");
+               return -1;
+       }
+
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -2264,6 +2550,14 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("H   - Start TCP Dump\n");
                printf("I   - Stop TCP Dump\n");
                printf("J   - Get TCP Dump State\n");
+               printf("K   - Enable MPTCP (internal)\n");
+               printf("L   - Disable MPTCP (internal)\n");
+               printf("M   - Set MPTCP Path Manager (internal)\n");
+               printf("N   - Get MPTCP Path Manager (internal)\n");
+               printf("O   - Set MPTCP Scheduler (internal)\n");
+               printf("P   - Get MPTCP Scheduler (internal)\n");
+               printf(LOG_GREEN "Q   - Create Handle and set callbacks in C# API\n" LOG_END);
+               printf("R   - Destroy Handle(unset callbacks automatically in C# API)\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
                printf("ENTER   - Show options menu.......\n");
        }
@@ -2397,6 +2691,30 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'J':
                rv = test_get_tcpdump_state();
                break;
+       case 'K':
+               rv = test_mptcp_enable();
+               break;
+       case 'L':
+               rv = test_mptcp_disable();
+               break;
+       case 'M':
+               rv = test_mptcp_set_path_manager();
+               break;
+       case 'N':
+               rv = test_mptcp_get_path_manager();
+               break;
+       case 'O':
+               rv = test_mptcp_set_scheduler();
+               break;
+       case 'P':
+               rv = test_mptcp_get_scheduler();
+               break;
+       case 'Q':
+               rv = test_register_client_cs();
+               break;
+       case 'R':
+               rv = test_deregister_client_cs();
+               break;
 
        }