Added connection_profile_get_dhcp_lease_duration API
[platform/core/api/connection.git] / test / connection_test.c
index 1c53099..087ce68 100755 (executable)
@@ -533,9 +533,35 @@ static int test_update_wifi_info(connection_profile_h profile)
        return 1;
 }
 
+static int test_update_dns_info(connection_profile_h profile,
+               connection_address_family_e address_family)
+{
+       int rv = 0;
+       char input_str[100] = {0,};
+       if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
+               rv = connection_profile_set_dns_address(profile,
+                               1,
+                               address_family,
+                               input_str);
+               if (rv != CONNECTION_ERROR_NONE)
+                       return -1;
+
+               if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
+                       rv = connection_profile_set_dns_address(profile,
+                                       2,
+                                       address_family,
+                                       input_str);
+                       if (rv != CONNECTION_ERROR_NONE)
+                               return -1;
+               }
+       }
+       return 1;
+}
+
 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
 {
        int rv = 0;
+       int input_int = 0;
        char input_str[100] = {0,};
 
        if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
@@ -554,32 +580,25 @@ static int test_update_ip_info(connection_profile_h profile, connection_address_
                        return -1;
        }
 
-       if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
-               rv = connection_profile_set_gateway_address(profile,
+       if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
+               rv = connection_profile_set_prefix_length(profile,
                                                        address_family,
-                                                       input_str);
+                                                       input_int);
                if (rv != CONNECTION_ERROR_NONE)
                        return -1;
        }
 
-       if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
-               rv = connection_profile_set_dns_address(profile,
-                                                       1,
+       if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
+               rv = connection_profile_set_gateway_address(profile,
                                                        address_family,
                                                        input_str);
                if (rv != CONNECTION_ERROR_NONE)
                        return -1;
-
-               if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
-                       rv = connection_profile_set_dns_address(profile,
-                                                               2,
-                                                               address_family,
-                                                               input_str);
-                       if (rv != CONNECTION_ERROR_NONE)
-                               return -1;
-               }
        }
 
+       if (test_update_dns_info(profile, address_family) < 0)
+               return -1;
+
        return 1;
 }
 
@@ -630,10 +649,13 @@ static int test_update_proxy_info(connection_profile_h profile, connection_addre
        return 1;
 }
 
+
+
 static int test_update_network_info(connection_profile_h profile)
 {
        int rv = 0;
        int input_int = 0;
+       int dns_input = 0;
        int address_family = 0;
 
        test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
@@ -643,8 +665,32 @@ static int test_update_network_info(connection_profile_h profile)
                switch (input_int) {
                case 1:
                        rv = connection_profile_set_ip_config_type(profile,
-                                                                  address_family,
-                                                                  CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
+                                       address_family,
+                                       CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
+                       if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
+                                               " - (Enter for skip) :", &dns_input)) {
+                               switch (dns_input) {
+                               case CONNECTION_DNS_CONFIG_TYPE_STATIC:
+                                       rv = connection_profile_set_dns_config_type(
+                                                       profile,
+                                                       address_family,
+                                                       CONNECTION_DNS_CONFIG_TYPE_STATIC);
+                                       if (rv != CONNECTION_ERROR_NONE)
+                                               return -1;
+                                       if (test_update_dns_info(profile,
+                                                               address_family) == -1)
+                                               return -1;
+                                       break;
+                               case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
+                                       rv = connection_profile_set_dns_config_type(
+                                                       profile,
+                                                       address_family,
+                                                       CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
+                                       if (rv != CONNECTION_ERROR_NONE)
+                                               return -1;
+                                       break;
+                               }
+                       }
                        break;
                case 2:
                        rv = connection_profile_set_ip_config_type(profile,
@@ -810,14 +856,18 @@ static void test_print_wifi_info(connection_profile_h profile)
 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
 {
        char *interface_name = NULL;
-       connection_ip_config_type_e ip_type;
        char *ip = NULL;
        char *subnet = NULL;
        char *gateway = NULL;
+       char *dhcp_server = NULL;
+       int dhcp_lease_duration = 0;
        char *dns1 = NULL;
        char *dns2 = NULL;
-       connection_proxy_type_e proxy_type;
        char *proxy = NULL;
+       int prefix_len;
+       connection_ip_config_type_e ip_type;
+       connection_proxy_type_e proxy_type;
+       connection_dns_config_type_e dns_type;
 
        if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
                printf("Fail to get interface name!\n");
@@ -838,6 +888,26 @@ static void test_print_network_info(connection_profile_h profile, connection_add
                g_free(ip);
        }
 
+       if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
+               printf("Fail to get gateway!\n");
+       else {
+               printf("Gateway : %s\n", gateway);
+               g_free(gateway);
+       }
+
+       if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
+               printf("Fail to get DHCP Server address!\n");
+       else {
+               printf("DHCP Server : %s\n", dhcp_server);
+               g_free(dhcp_server);
+       }
+
+       if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
+               printf("Fail to get DHCP lease duration!\n");
+       else {
+               printf("DHCP lease duration : %d\n", dhcp_lease_duration);
+       }
+
        if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
                printf("Fail to get subnet mask!\n");
        else {
@@ -845,12 +915,15 @@ static void test_print_network_info(connection_profile_h profile, connection_add
                g_free(subnet);
        }
 
-       if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
-               printf("Fail to get gateway!\n");
-       else {
-               printf("Gateway : %s\n", gateway);
-               g_free(gateway);
-       }
+       if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
+               printf("Fail to get prefix length!\n");
+       else
+               printf("Prefix length : %d\n", prefix_len);
+
+       if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
+               printf("Fail to get DNS configuration type!\n");
+       else
+               printf("DNS configuration type : %d\n", dns_type);
 
        if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
                printf("Fail to get DNS1!\n");
@@ -1416,6 +1489,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_profile_h profile;
        char *profile_name = NULL;
        int address_family = 0;
@@ -1433,11 +1507,18 @@ int test_get_profile_info(void)
        }
 
        if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
-               printf("Fail to get profile state\n");
+               printf("Fail to get profile IPv4 state\n");
                return -1;
        } else
                printf("Profile State : %s\n", test_print_state(profile_state));
 
+       if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
+               printf("Fail to get profile IPv6 state\n");
+               return -1;
+       } else
+               printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
+
+
        if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
                return -1;
 
@@ -1738,6 +1819,147 @@ int test_remove_route_ipv6(void)
        return 1;
 }
 
+int test_add_route_entry(void)
+{
+       char ip_addr[100] = {0};
+       char gateway[100] = {0};
+       char if_name[40] = {0};
+       int input;
+       bool input_rv;
+       int rv = 0;
+
+       input_rv = test_get_user_int("Input Address type to get"
+               "(1:IPV4, 2:IPV6):", &input);
+
+       if (input_rv == false) {
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       switch (input) {
+       case 1:
+               if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+                       return -1;
+
+               if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
+                       return -1;
+
+               if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
+                       return -1;
+
+               g_strstrip(ip_addr);
+               g_strstrip(gateway);
+               g_strstrip(if_name);
+               rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
+               if (rv != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get add new route [%d]\n", rv);
+                       return -1;
+               }
+               printf("Add Route successfully\n");
+               break;
+
+       case 2:
+               if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+                       return -1;
+
+               if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
+                       return -1;
+
+               if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
+                       return -1;
+
+               g_strstrip(ip_addr);
+               g_strstrip(gateway);
+               g_strstrip(if_name);
+               rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
+               if (rv != CONNECTION_ERROR_NONE) {
+                       printf("Fail to get add new route [%d]\n", rv);
+                       return -1;
+               }
+               printf("Add Route successfully\n");
+               break;
+
+       default:
+               printf("Wrong IP address family!!\n");
+               return -1;
+
+       }
+
+       return 1;
+
+}
+
+int test_remove_route_entry(void)
+{
+       char ip_addr[100] = {0};
+       char gateway[100] = {0};
+       char if_name[40] = {0};
+       int input;
+       bool input_rv;
+       int rv = 0;
+
+       input_rv = test_get_user_int("Input Address type to get"
+               "(1:IPV4, 2:IPV6):", &input);
+
+       if (input_rv == false) {
+               printf("Invalid input!!\n");
+               return -1;
+       }
+
+       switch (input) {
+       case 1:
+               if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+                       return -1;
+
+               if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
+                       return -1;
+
+               if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
+                       return -1;
+
+               g_strstrip(ip_addr);
+               g_strstrip(gateway);
+               g_strstrip(if_name);
+               rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
+               if (rv != CONNECTION_ERROR_NONE) {
+                       printf("Fail to remove the route [%s]\n", test_print_error(rv));
+                       return -1;
+               }
+               printf("Remove Route successfully\n");
+
+               break;
+
+       case 2:
+               if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+                       return -1;
+
+               if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
+                       return -1;
+
+               if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
+                       return -1;
+
+               g_strstrip(ip_addr);
+               g_strstrip(gateway);
+               g_strstrip(if_name);
+               rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
+               if (rv != CONNECTION_ERROR_NONE) {
+                       printf("Fail to remove the route [%d]\n", rv);
+                       return -1;
+               }
+               printf("Remove Route successfully\n");
+               break;
+
+       default:
+               printf("Wrong IP address family!!\n");
+               return -1;
+
+       }
+
+       return 1;
+
+}
+
 int test_get_bt_state(void)
 {
        int rv = 0;
@@ -1850,6 +2072,42 @@ int test_reset_profile(void)
        return 1;
 }
 
+static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
+{
+       printf("IPv6 Address : %s\n", ipv6_address);
+       return true;
+}
+
+int test_foreach_ipv6_address(void)
+{
+       int rv = 0;
+       int type;
+       connection_type_e conn_type;
+
+       test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
+
+       switch (type) {
+       case 1:
+               conn_type = CONNECTION_TYPE_WIFI;
+               break;
+       case 2:
+               conn_type = CONNECTION_TYPE_ETHERNET;
+               break;
+       default:
+               printf("Wrong number!!\n");
+               return -1;
+       }
+
+       rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Fail to get IPv6 address\n");
+               return -1;
+       }
+
+       return 1;
+}
+
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -1920,6 +2178,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("x   - Get ethernet cable state\n");
                printf("B   - Add IPv6 new route\n");
                printf("C   - Remove IPv6 route\n");
+               printf("D   - Add new route entry\n");
+               printf("E   - Remove route entry\n");
+               printf("F   - Get all IPv6 address\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
                printf("ENTER   - Show options menu.......\n");
        }
@@ -2030,6 +2291,15 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'C':
                rv = test_remove_route_ipv6();
                break;
+       case 'D':
+               rv = test_add_route_entry();
+               break;
+       case 'E':
+               rv = test_remove_route_entry();
+               break;
+       case 'F':
+               rv = test_foreach_ipv6_address();
+               break;
        }
 
        if (rv == 1)