Merge "Added APIs get the tcp dump and network state" into tizen
[platform/core/api/connection.git] / test / connection_test.c
index 581f28f..b931a52 100755 (executable)
@@ -22,6 +22,7 @@
 #include <glib.h>
 
 #include "net_connection.h"
+#include "connection_extension.h"
 
 #include <tizen_error.h>
 
@@ -859,6 +860,8 @@ static void test_print_network_info(connection_profile_h profile, connection_add
        char *ip = NULL;
        char *subnet = NULL;
        char *gateway = NULL;
+       char *dhcp_server = NULL;
+       int dhcp_lease_duration = 0;
        char *dns1 = NULL;
        char *dns2 = NULL;
        char *proxy = NULL;
@@ -893,6 +896,19 @@ static void test_print_network_info(connection_profile_h profile, connection_add
                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 {
@@ -2092,6 +2108,58 @@ int test_foreach_ipv6_address(void)
        return 1;
 }
 
+int test_is_metered_network(void)
+{
+       int rv = 0;
+       bool metered_state;
+
+       rv = connection_is_metered_network(connection, &metered_state);
+
+       if (rv != CONNECTION_ERROR_NONE) {
+               printf("Fail to get metered state [%s]\n", test_print_error(rv));
+               return -1;
+       }
+
+       printf("Retval = [%s] metered state [%s]\n",
+               test_print_error(rv), metered_state ? "TRUE" : "FALSE");
+
+       return 1;
+}
+
+int test_start_tcpdump(void)
+{
+       if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("Successfully started tcpdump\n");
+
+       return 1;
+}
+
+int test_stop_tcpdump(void)
+{
+       if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("Successfully stopped tcpdump\n");
+
+       return 1;
+}
+
+int test_get_tcpdump_state(void)
+{
+       gboolean tcpdump_state = FALSE;
+
+       if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
+
+       return 1;
+}
 
 int main(int argc, char **argv)
 {
@@ -2126,8 +2194,10 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        }
 
        if (*a == '\n' || *a == '\r') {
+/* Public API */
                printf("\n\n Network Connection API Test App\n\n");
                printf("Options..\n");
+               printf(LOG_BLUE "[Public APIs]\n" LOG_END);
                printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
                printf("2   - Destroy Handle(unset callbacks automatically)\n");
                printf(LOG_GREEN "3   - Get network state\n" LOG_END);
@@ -2163,12 +2233,21 @@ 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   - Get IPv6 address\n");
+               printf("D   - Add new route entry\n");
+               printf("E   - Remove route entry\n");
+               printf("F   - Get all IPv6 address\n");
+               printf("G   - Get metered state\n");
+/* Extension API */
+               printf(LOG_BLUE "[Extension API]\n" LOG_END);
+               printf("H   - Start TCP Dump\n");
+               printf("I   - Stop TCP Dump\n");
+               printf("J   - Get TCP Dump State\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
                printf("ENTER   - Show options menu.......\n");
        }
 
        switch (a[0]) {
+/* Public API */
        case '1':
                rv = test_register_client();
                break;
@@ -2283,6 +2362,20 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'F':
                rv = test_foreach_ipv6_address();
                break;
+       case 'G':
+               rv = test_is_metered_network();
+               break;
+/* Extension API */
+       case 'H':
+               rv = test_start_tcpdump();
+               break;
+       case 'I':
+               rv = test_stop_tcpdump();
+               break;
+       case 'J':
+               rv = test_get_tcpdump_state();
+               break;
+
        }
 
        if (rv == 1)