Implement APIs for IPv6 and DNS configuration
[platform/core/api/connection.git] / test / connection_test.c
index 7d6007f..38ab325 100755 (executable)
@@ -170,26 +170,28 @@ static const char *test_print_cellular_service_type(connection_cellular_service_
 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
 {
        switch (type) {
-       case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
-               return "None";
        case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
                return "PAP";
        case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
                return "CHAP";
+       case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
+       default:
+               return "None";
        }
 }
 
 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
 {
        switch (type) {
-       case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
-               return "Unknown";
        case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
                return "IPv4";
        case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
                return "IPv6";
        case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
                return "Dual";
+       case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
+       default:
+               return "Unknown";
        }
 }
 
@@ -348,28 +350,22 @@ static bool test_get_user_selected_profile(connection_profile_h *profile, bool s
                        return false;
                }
 
-               if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
-                       char *essid;
-                       connection_profile_get_wifi_essid(profile_h, &essid);
-                       printf("%d. state:[%s], profile name:%s, essid:%s\n",
-                               profile_count, test_print_state(profile_state),
-                               profile_name, (essid) ? essid : "");
-                       g_free(essid);
-
-                       profile_list[profile_count] = profile_h;
-                       profile_count++;
-               } else {
+               printf("%d. state:[%s], profile name:%s", profile_count,
+                               test_print_state(profile_state), profile_name);
+               if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
                        connection_cellular_service_type_e service_type;
-                       if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE)
+                       if (connection_profile_get_cellular_service_type(
+                               profile_h, &service_type) !=
+                               CONNECTION_ERROR_NONE)
                                printf("Fail to get cellular service type!\n");
 
-                       printf("%d. state:[%s], profile name:%s[%s]\n",
-                               profile_count, test_print_state(profile_state),
-                               profile_name, test_print_cellular_service_type(service_type));
-
-                       profile_list[profile_count] = profile_h;
-                       profile_count++;
+                       printf("[%s]",
+                               test_print_cellular_service_type(service_type));
                }
+               printf("\n");
+
+               profile_list[profile_count] = profile_h;
+               profile_count++;
 
                g_free(profile_name);
                if (profile_count >= 100)
@@ -537,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)) {
@@ -558,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;
 }
 
@@ -634,21 +649,48 @@ 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);
 
-       if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
+       if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
                                " - (Enter for skip) :", &input_int)) {
                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,
@@ -663,6 +705,11 @@ static int test_update_network_info(connection_profile_h profile)
                        if (test_update_proxy_info(profile, address_family) == -1)
                                return -1;
                        break;
+               case 3:
+                       rv = connection_profile_set_ip_config_type(profile,
+                                                               address_family,
+                                                               CONNECTION_IP_CONFIG_TYPE_AUTO);
+                       break;
                default:
                        return -1;
                }
@@ -809,14 +856,16 @@ 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 *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");
@@ -837,6 +886,13 @@ 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_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
                printf("Fail to get subnet mask!\n");
        else {
@@ -844,12 +900,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");
@@ -1415,6 +1474,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;
@@ -1432,11 +1492,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;