Add gtest for line coverage 64/240864/7
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 12 Aug 2020 07:34:39 +0000 (16:34 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 14 Aug 2020 02:33:22 +0000 (11:33 +0900)
Change-Id: I3aba1c4f16dc09c429a49c27b082765c4475b960

18 files changed:
CMakeLists.txt
packaging/capi-vpn-service.spec
src/capi_vpn_service.c
tests/CMakeLists.txt [new file with mode: 0644]
tests/mocks/vpn_service_file.c [new file with mode: 0644]
tests/mocks/vpn_service_file.h [new file with mode: 0644]
tests/mocks/vpn_service_gdbus.c [new file with mode: 0644]
tests/mocks/vpn_service_gdbus.h [new file with mode: 0644]
tests/mocks/vpn_service_io.c [new file with mode: 0644]
tests/mocks/vpn_service_io.h [new file with mode: 0644]
tests/mocks/vpn_service_system_info.c [new file with mode: 0644]
tests/mocks/vpn_service_system_info.h [new file with mode: 0644]
tests/vpn-service-gtest-common.cpp [new file with mode: 0755]
tests/vpn-service-gtest-internal.cpp [new file with mode: 0755]
tests/vpn-service-gtest-main.cpp [new file with mode: 0755]
tools/CMakeLists.txt [moved from test/CMakeLists.txt with 99% similarity]
tools/vpn_service_test.c [moved from test/vpn_service_test.c with 100% similarity]
tools/vpnsvc-test.manifest [moved from test/vpnsvc-test.manifest with 100% similarity]

index 3de910a..dff581b 100755 (executable)
@@ -63,4 +63,7 @@ CONFIGURE_FILE(
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig)
 
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tools)
+IF(BUILD_GTESTS)
+       ADD_SUBDIRECTORY(tests)
+ENDIF(BUILD_GTESTS)
index 7fa70a8..77ff795 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       vpnsvc-pkg
 Summary:    VPN service library in TIZEN C API
-Version:    1.0.28
+Version:    1.1.0
 Release:    1
 Group:      System/Network
 License:    Apache-2.0
@@ -15,8 +15,10 @@ BuildRequires:  pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(capi-appfw-package-manager)
 BuildRequires:  pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(gmock)
 %if 0%{?gcov:1}
 BuildRequires: lcov
+BuildRequires: tar
 %endif
 
 Requires(post): /sbin/ldconfig
@@ -41,13 +43,6 @@ Requires: capi-vpnsvc
 %description -n capi-vpnsvc-devel
 capi-vpnsvc CAPI devel package
 
-#%package -n vpnsvc_test
-#Summary:  Vpnsvc test
-#Group:    Development/Libraries
-
-#%description -n vpnsvc_test
-#vpnsvc test package
-
 %if 0%{?gcov:1}
 %package gcov
 Summary:  VPN service library(gcov)
@@ -73,9 +68,10 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DVERSION=%{version} \
        -DFULLVER=%{version} \
        -DMAJORVER=${MAJORVER} \
-        -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
-        -DCMAKE_VERBOSE_MAKEFILE=ON \
-        -DLIB_INSTALL_DIR=%{_libdir}
+       -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
+       -DCMAKE_VERBOSE_MAKEFILE=ON \
+       -DLIB_INSTALL_DIR=%{_libdir} \
+       -DBUILD_GTESTS=%{?gcov:1}%{!?gcov:0}
 
 make %{?jobs:-j%jobs}
 
@@ -85,17 +81,21 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
 %endif
 
 %install
-rm -rf %{buildroot}
-
 %make_install
 
 %if 0%{?gcov:1}
-mkdir -p %{buildroot}%{_datadir}/gcov/obj
-install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+find .. -name '*.gcno' | tar cf %{name}-gcov.tar -T -
+install -d -m 755 %{buildroot}%{_datadir}/gcov/obj
+tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
 %endif
 
-%clean
-rm -rf %{buildroot}
+%check
+%if 0%{?gcov:1}
+tests/vpn-service-gtest
+
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
+%endif
 
 %post -n capi-vpnsvc -p /sbin/ldconfig
 
@@ -112,10 +112,6 @@ rm -rf %{buildroot}
 %{_libdir}/pkgconfig/capi-vpnsvc.pc
 %{_libdir}/libcapi-vpnsvc.so
 
-#%files -n vpnsvc_test
-#%manifest test/vpnsvc-test.manifest
-#%{_bindir}/vpnsvc_test
-
 %if 0%{?gcov:1}
 %files gcov
 %{_datadir}/gcov/obj/*
index 6e180c7..d901519 100755 (executable)
@@ -42,19 +42,19 @@ int _vpnsvc_check_feature_supported(const char *feature_name)
 {
        if (is_feature_checked) {
                if (!feature_supported) {
-                       LOGE("%s feature is disabled", feature_name); //LCOV_EXCL_LINE
-                       return VPNSVC_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
+                       LOGE("%s feature is disabled", feature_name);
+                       return VPNSVC_ERROR_NOT_SUPPORTED;
                }
        } else {
                if (!system_info_get_platform_bool(feature_name, &feature_supported)) {
                        is_feature_checked = true;
                        if (!feature_supported) {
-                               LOGE("%s feature is disabled", feature_name); //LCOV_EXCL_LINE
-                               return VPNSVC_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
+                               LOGE("%s feature is disabled", feature_name);
+                               return VPNSVC_ERROR_NOT_SUPPORTED;
                        }
                } else {
-                       LOGE("Error - Feature getting from System Info"); //LCOV_EXCL_LINE
-                       return VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+                       LOGE("Error - Feature getting from System Info");
+                       return VPNSVC_ERROR_IO_ERROR;
                }
        }
 
@@ -87,8 +87,8 @@ static void _vpnsvc_init_vpnsvc_tun_s(vpnsvc_tun_s **s)
 
        if (s == NULL) return;
        if (*s != NULL) {
-               LOGE("Can't Initialize vpnsvc_tun_s: %p", *s); //LCOV_EXCL_LINE
-               return; //LCOV_EXCL_LINE
+               LOGE("Can't Initialize vpnsvc_tun_s: %p", *s);
+               return;
        }
        *s = (vpnsvc_tun_s*)g_malloc0(sizeof(vpnsvc_tun_s));
 
@@ -102,8 +102,8 @@ static void _vpnsvc_init_vpnsvc_tun_s(vpnsvc_tun_s **s)
 
                connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
                if (error != NULL) {
-                       LOGE("Error creating Connection: %s", error->message); //LCOV_EXCL_LINE
-                       g_error_free(error); //LCOV_EXCL_LINE
+                       LOGE("Error creating Connection: %s", error->message);
+                       g_error_free(error);
                } else {
                        LOGD("Created Connection: %p", connection);
                        (*s)->connection = connection;
@@ -158,9 +158,9 @@ GVariant *_vpnsvc_invoke_dbus_method(GDBusConnection *connection,
        LOGD("Method Call() dest=%s path=%s iface=%s method=%s", dest, path, interface_name, method);
 
        if (connection == NULL) {
-               LOGD("GDBusconnection is NULL"); //LCOV_EXCL_LINE
-               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
-               return reply; //LCOV_EXCL_LINE
+               LOGD("GDBusconnection is NULL");
+               *dbus_error = VPNSVC_ERROR_IO_ERROR;
+               return reply;
        }
 
        reply = g_dbus_connection_call_sync(connection,
@@ -176,17 +176,17 @@ GVariant *_vpnsvc_invoke_dbus_method(GDBusConnection *connection,
                                                                                &error);
 
        if (reply == NULL) {
-               if (error != NULL) {//LCOV_EXCL_LINE
-                       LOGE("g_dbus_connection_call_sync() failed "//LCOV_EXCL_LINE
+               if (error != NULL) {
+                       LOGE("g_dbus_connection_call_sync() failed "
                                "error [%d: %s]", error->code, error->message);
-                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED) //LCOV_EXCL_LINE
-                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED;
                        else
-                               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
-                       g_error_free(error);//LCOV_EXCL_LINE
+                               *dbus_error = VPNSVC_ERROR_IO_ERROR;
+                       g_error_free(error);
                } else {
-                       LOGE("g_dbus_connection_call_sync() failed");//LCOV_EXCL_LINE
-                       *dbus_error = VPNSVC_ERROR_IPC_FAILED;//LCOV_EXCL_LINE
+                       LOGE("g_dbus_connection_call_sync() failed");
+                       *dbus_error = VPNSVC_ERROR_IPC_FAILED;
                }
 
                return NULL;
@@ -207,24 +207,25 @@ GVariant *_vpnsvc_invoke_dbus_method_with_fd(GDBusConnection *connection,
        LOGD("Method Call() dest=%s path=%s iface=%s method=%s fd=%d", dest, path, interface_name, method, fd);
 
        if (connection == NULL) {
-               LOGD("GDBusconnection is NULL"); //LCOV_EXCL_LINE
-               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
-               return reply; //LCOV_EXCL_LINE
+               LOGD("GDBusconnection is NULL");
+               *dbus_error = VPNSVC_ERROR_IO_ERROR;
+               return reply;
        }
 
        /* Setting the fd_list */
        fd_list = g_unix_fd_list_new();
        if (fd_list == NULL) {
-               LOGE("g_unix_fd_list_new() failed!"); //LCOV_EXCL_LINE
-               return NULL; //LCOV_EXCL_LINE
+               LOGE("g_unix_fd_list_new() failed!");
+               return NULL;
        }
+
        g_unix_fd_list_append(fd_list, fd, &error);
        if (error != NULL) {
-               LOGE("g_unix_fd_list_append() failed" //LCOV_EXCL_LINE
+               LOGE("g_unix_fd_list_append() failed"
                                "error [%d: %s]", error->code, error->message);
-               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
-               g_error_free(error); //LCOV_EXCL_LINE
-               return NULL; //LCOV_EXCL_LINE
+               *dbus_error = VPNSVC_ERROR_IO_ERROR;
+               g_error_free(error);
+               return NULL;
        }
 
        reply = g_dbus_connection_call_with_unix_fd_list_sync(connection,
@@ -242,17 +243,17 @@ GVariant *_vpnsvc_invoke_dbus_method_with_fd(GDBusConnection *connection,
                                                                                                                &error);
 
        if (reply == NULL) {
-               if (error != NULL) {//LCOV_EXCL_LINE
-                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed " //LCOV_EXCL_LINE
+               if (error != NULL) {
+                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed "
                                        "error [%d: %s]", error->code, error->message);
-                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED) //LCOV_EXCL_LINE
-                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED;
                        else
-                               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
-                       g_error_free(error); //LCOV_EXCL_LINE
+                               *dbus_error = VPNSVC_ERROR_IO_ERROR;
+                       g_error_free(error);
                } else {
-                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed"); //LCOV_EXCL_LINE
-                       *dbus_error = VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed");
+                       *dbus_error = VPNSVC_ERROR_IPC_FAILED;
                }
 
                return NULL;
@@ -268,9 +269,14 @@ EXPORT_API int vpnsvc_create(vpnsvc_h *handle)
        LOGD("enter vpnsvc_create");
 
        /* parameter check */
+       if (handle == NULL) {
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
+       }
+
        if (_vpn_check_handle_validity(*handle)) {
-               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Invalid parameter");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        vpnsvc_tun_s *tmp_s = NULL;
@@ -290,8 +296,8 @@ EXPORT_API int vpnsvc_destroy(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
@@ -314,20 +320,20 @@ EXPORT_API int vpnsvc_init(const char* iface_name, vpnsvc_h *handle)
 
        /* parameter check */
        if (iface_name == NULL || strlen(iface_name) <= 0) {
-               LOGE("iface_name is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
-       } else if (_vpn_check_handle_validity(*handle)) {
-               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("iface_name is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
+       } else if (handle == NULL || _vpn_check_handle_validity(*handle)) {
+               LOGE("Invalid parameter");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        vpnsvc_tun_s *tmp_s = NULL;
        _vpnsvc_init_vpnsvc_tun_s(&tmp_s);
 
        if ((iface_fd = open("/dev/net/tun", O_RDWR)) < 0) {
-               LOGE("tun device open fail\n"); //LCOV_EXCL_LINE
-               _vpnsvc_deinit_vpnsvc_tun_s(tmp_s); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+               LOGE("tun device open fail\n");
+               _vpnsvc_deinit_vpnsvc_tun_s(tmp_s);
+               return VPNSVC_ERROR_IO_ERROR;
        }
 
        LOGD("client iface_fd : %d", iface_fd);
@@ -362,19 +368,19 @@ EXPORT_API int vpnsvc_init(const char* iface_name, vpnsvc_h *handle)
        }
 
        if (op == NULL) {
-               close(iface_fd); //LCOV_EXCL_LINE
-               _vpnsvc_deinit_vpnsvc_tun_s(tmp_s); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               close(iface_fd);
+               _vpnsvc_deinit_vpnsvc_tun_s(tmp_s);
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                int tmp_index;
                char* tmp_name;
 
                g_variant_get(op, "(iis)", &result, &tmp_index, &tmp_name);
                if (result != VPNSVC_ERROR_NONE) {
-                       LOGE("vpnsvc_init() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpnsvc_init() failed");
                        close(iface_fd);
-                       _vpnsvc_deinit_vpnsvc_tun_s(tmp_s); //LCOV_EXCL_LINE
-                       result = VPNSVC_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+                       _vpnsvc_deinit_vpnsvc_tun_s(tmp_s);
+                       result = VPNSVC_ERROR_PERMISSION_DENIED;
                } else {
                        LOGD("vpnsvc_init() succeed");
                        tmp_s->fd = iface_fd;   /* client fd must be set */
@@ -405,8 +411,8 @@ EXPORT_API int vpnsvc_deinit(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
@@ -436,18 +442,18 @@ EXPORT_API int vpnsvc_deinit(vpnsvc_h handle)
                        return VPNSVC_ERROR_PERMISSION_DENIED;
 
                if (op == NULL) {
-                       return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+                       return VPNSVC_ERROR_IPC_FAILED;
                } else {
                        g_variant_get(op, "(i)", &result);
                        if (result != VPNSVC_ERROR_NONE)
-                               LOGE("vpn_deinit() failed"); //LCOV_EXCL_LINE
+                               LOGE("vpn_deinit() failed");
                        else
                                LOGD("vpn_deinit() succeed");
                }
 
                if (close(tun_s->fd) != 0) {
-                       LOGE("tun fd close : %s", strerror_r(errno, buf, BUF_SIZE_FOR_ERR)); //LCOV_EXCL_LINE
-                       return VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+                       LOGE("tun fd close : %s", strerror_r(errno, buf, BUF_SIZE_FOR_ERR));
+                       return VPNSVC_ERROR_IO_ERROR;
                } else
                        LOGD("tun fd close success");
 
@@ -468,17 +474,16 @@ EXPORT_API int vpnsvc_protect(vpnsvc_h handle, int socket_fd, const char* iface_
        vpnsvc_tun_s *tun_s = NULL;
 
        /* parameter check */
-       if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
-       }
+       if (handle == NULL || socket_fd < 0 || iface_name == NULL)
+               return VPNSVC_ERROR_INVALID_PARAMETER;
+
        tun_s = (vpnsvc_tun_s*)handle;
 
        LOGD("enter vpnsvc_protect, socket : %d, dev_name : %s", socket_fd, iface_name);
 
        if (tun_s->connection == NULL) {
-               LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Connection Object is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -506,12 +511,12 @@ EXPORT_API int vpnsvc_protect(vpnsvc_h handle, int socket_fd, const char* iface_
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
 
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_protect() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_protect() failed");
                else
                        LOGD("vpn_protect() succeed");
        }
@@ -529,19 +534,19 @@ EXPORT_API int vpnsvc_up(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        LOGD("enter vpnsvc_up");
 
        if (tun_s->connection == NULL) {
-               LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Connection Object is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        } else if (tun_s->name[0] == 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        LOGD("iface_index %d, iface_name %s", tun_s->index, tun_s->name);
@@ -569,11 +574,11 @@ EXPORT_API int vpnsvc_up(vpnsvc_h handle)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_up() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_up() failed");
                else
                        LOGD("vpn_up() succeed");
        }
@@ -591,16 +596,16 @@ EXPORT_API int vpnsvc_down(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        LOGD("enter vpnsvc_down");
 
        if (tun_s->connection == NULL) {
-               LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Connection Object is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -626,11 +631,11 @@ EXPORT_API int vpnsvc_down(vpnsvc_h handle)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_down() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_down() failed");
                else
                        LOGD("vpn_down() succeed");
        }
@@ -651,14 +656,20 @@ EXPORT_API int vpnsvc_read(vpnsvc_h handle, int timeout_ms)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
+       }
+
+       if (timeout_ms < 0) {
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
+
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (tun_s->fd <= 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        /* listen for events */
@@ -672,11 +683,11 @@ EXPORT_API int vpnsvc_read(vpnsvc_h handle, int timeout_ms)
                LOGD("Data is available now.\n");
                ret = VPNSVC_ERROR_NONE;
        } else if (retVal == 0) {
-               LOGD("No data within %d ms\n", timeout_ms); //LCOV_EXCL_LINE
-               ret = VPNSVC_ERROR_TIMEOUT; //LCOV_EXCL_LINE
+               LOGD("No data within %d ms\n", timeout_ms);
+               ret = VPNSVC_ERROR_TIMEOUT;
        } else {
-               LOGE("select failed\n"); //LCOV_EXCL_LINE
-               ret = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+               LOGE("select failed\n");
+               ret = VPNSVC_ERROR_IO_ERROR;
        }
 
        return ret;
@@ -691,14 +702,15 @@ EXPORT_API int vpnsvc_write(vpnsvc_h handle, const char* data, size_t size)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
+
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (tun_s->fd <= 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        return write(tun_s->fd, data, size);
@@ -726,8 +738,8 @@ EXPORT_API int vpnsvc_block_networks(vpnsvc_h handle,
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        if (num_allow_routes_vpn > MAX_NUM_ROUTES || num_allow_routes_orig > MAX_NUM_ROUTES) {
@@ -740,12 +752,12 @@ EXPORT_API int vpnsvc_block_networks(vpnsvc_h handle,
        LOGD("enter vpnsvc_block_networks");
 
        if (tun_s->connection == NULL) {
-               LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Connection Object is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        /* make a route parameter for allowed VPN interface routes */
        g_variant_builder_init(&nets_builder, G_VARIANT_TYPE("a{si}"));
-       for (i = 0 ; i < num_allow_routes_vpn ; i++) {
+       for (i = 0 ;i < num_allow_routes_vpn ; i++) {
                g_variant_builder_add(&nets_builder, "{si}", routes_dest_vpn_addr[i], routes_vpn_prefix[i]);
                LOGD("dest_vpn[%d] : %s", i, routes_dest_vpn_addr[i]);
                LOGD("prefix_vpn[%d] : %d", i,  routes_vpn_prefix[i]);
@@ -754,7 +766,7 @@ EXPORT_API int vpnsvc_block_networks(vpnsvc_h handle,
 
        /* make a route parameter for allowed Original interface Routes */
        g_variant_builder_init(&nets_builder, G_VARIANT_TYPE("a{si}"));
-       for (i = 0 ; i < num_allow_routes_orig ; i++) {
+       for (i = 0 ;i < num_allow_routes_orig ; i++) {
                g_variant_builder_add(&nets_builder, "{si}", routes_dest_orig_addr[i], routes_orig_prefix[i]);
                LOGD("dest_orig[%d] : %s", i, routes_dest_orig_addr[i]);
                LOGD("prefix_orig[%d] : %d", i,  routes_orig_prefix[i]);
@@ -785,11 +797,11 @@ EXPORT_API int vpnsvc_block_networks(vpnsvc_h handle,
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_block_networks() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_block_networks() failed");
                else
                        LOGD("vpn_block_networks() succeed");
        }
@@ -807,15 +819,15 @@ EXPORT_API int vpnsvc_unblock_networks(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        LOGD("enter vpnsvc_unblock_networks");
        if (tun_s->connection == NULL) {
-               LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Connection Object is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -841,11 +853,11 @@ EXPORT_API int vpnsvc_unblock_networks(vpnsvc_h handle)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_unblock_networks() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_unblock_networks() failed");
                else
                        LOGD("vpn_unblock_networks() succeed");
        }
@@ -863,8 +875,8 @@ EXPORT_API int vpnsvc_update_settings(vpnsvc_h handle)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        tun_s = (vpnsvc_tun_s*)handle;
@@ -886,11 +898,11 @@ EXPORT_API int vpnsvc_update_settings(vpnsvc_h handle)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_update_settings() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_update_settings() failed");
                else
                        LOGD("vpn_update_settings() succeed");
        }
@@ -906,14 +918,14 @@ EXPORT_API int vpnsvc_get_iface_fd(vpnsvc_h handle, int* iface_fd)
 
        /* parameter check */
        if (handle == NULL || iface_fd == NULL) {
-               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Invalid parameter");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (tun_s->fd <= 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        *iface_fd = (int)(tun_s->fd);
@@ -929,15 +941,15 @@ EXPORT_API int vpnsvc_get_iface_index(vpnsvc_h handle, int* iface_index)
 
        /* parameter check */
        if (handle == NULL || iface_index == NULL) {
-               LOGE("Invalid parameter"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Invalid parameter");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (tun_s->index <= 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        *iface_index = (int)(tun_s->index);
@@ -953,20 +965,20 @@ EXPORT_API int vpnsvc_get_iface_name(vpnsvc_h handle, char** iface_name)
        char la_iface_name[VPNSVC_VPN_IFACE_NAME_LEN + 1] = { 0, };
 
        /* parameter check */
-       if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       if (handle == NULL || iface_name == NULL) {
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (strlen(tun_s->name) <= 0) {
-               LOGE("invalid handle"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("invalid handle");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        if (iface_name == NULL) {
-               LOGE("tun name string is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("tun name string is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        g_strlcpy(la_iface_name, tun_s->name, VPNSVC_VPN_IFACE_NAME_LEN + 1);
@@ -983,14 +995,14 @@ EXPORT_API int vpnsvc_set_iface_name(vpnsvc_h handle, const char *iface_name)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (iface_name == NULL) {
-               LOGE("Remote IP address is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Remote IP address is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        g_strlcpy(tun_s->name, iface_name, VPNSVC_VPN_IFACE_NAME_LEN);
@@ -1008,14 +1020,14 @@ EXPORT_API int vpnsvc_set_mtu(vpnsvc_h handle, int mtu)
 
        /* parameter check */
        if (handle == NULL) {
-               LOGE("handle is a NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("handle is a NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (mtu <= 0) {
-               LOGE("Incorrect MTU Size = %d", mtu); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Incorrect MTU Size = %d", mtu);
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        tun_s->mtu = mtu;
@@ -1039,24 +1051,24 @@ EXPORT_API int vpnsvc_set_blocking(vpnsvc_h handle, bool blocking)
        int flags;
 
        if (tun_s->fd <= 0) {
-               LOGE("The Tunnel File Descriptor fd = %d", tun_s->fd); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("The Tunnel File Descriptor fd = %d", tun_s->fd);
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        flags = fcntl(tun_s->fd, F_GETFL);
        if (flags < 0) {
-               LOGD("File Descriptor Flags GET Failed fd = %d", tun_s->fd); //LCOV_EXCL_LINE
-               flags = 0; //LCOV_EXCL_LINE
+               LOGD("File Descriptor Flags GET Failed fd = %d", tun_s->fd);
+               flags = 0;
        }
 
        if (blocking == false)
-               flags = flags | O_NONBLOCK;//LCOV_EXCL_LINE
+               flags = flags | O_NONBLOCK;
        else
                flags = flags & (~O_NONBLOCK);
 
        if (fcntl(tun_s->fd, F_SETFL, flags) < 0) {
-               LOGE("Failed fd = %d F_SETFL(flags) = %d", tun_s->fd, flags); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+               LOGE("Failed fd = %d F_SETFL(flags) = %d", tun_s->fd, flags);
+               return VPNSVC_ERROR_IO_ERROR;
        }
        return VPNSVC_ERROR_NONE;
 }
@@ -1075,12 +1087,17 @@ EXPORT_API int vpnsvc_set_session(vpnsvc_h handle, const char* session)
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (session == NULL) {
-               LOGE("Session Name string is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Session Name string is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
+       }
+
+       if (strlen(session) >= VPNSVC_SESSION_STRING_LEN) {
+               LOGE("Session name is longer than 32");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        strncpy(tun_s->session, session, VPNSVC_SESSION_STRING_LEN);
-       tun_s->session[VPNSVC_SESSION_STRING_LEN-1] = '\0';
+       tun_s->session[VPNSVC_SESSION_STRING_LEN - 1] = '\0';
 
        return VPNSVC_ERROR_NONE;
 }
@@ -1100,8 +1117,8 @@ EXPORT_API int vpnsvc_get_session(vpnsvc_h handle, char** session)
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (session == NULL) {
-               LOGE("Session Name string is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Session Name string is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        g_strlcpy(la_session, tun_s->session, VPNSVC_SESSION_STRING_LEN + 1);
@@ -1124,12 +1141,12 @@ EXPORT_API int vpnsvc_set_local_ip_address(vpnsvc_h handle, const char *local_ip
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (local_ip == NULL) {
-               LOGE("Local IP address is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Local IP address is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        g_strlcpy(tun_s->local_ip, local_ip, VPNSVC_IP4_STRING_LEN);
-       
+
        return VPNSVC_ERROR_NONE;
 }
 
@@ -1147,8 +1164,8 @@ EXPORT_API int vpnsvc_set_remote_ip_address(vpnsvc_h handle, const char *remote_
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (remote_ip == NULL) {
-               LOGE("Remote IP address is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("Remote IP address is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        g_strlcpy(tun_s->remote_ip, remote_ip, VPNSVC_IP4_STRING_LEN);
@@ -1172,8 +1189,8 @@ EXPORT_API int vpnsvc_add_route(vpnsvc_h handle, const char *route_address, int
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (route_address == NULL) {
-               LOGE("remove_address is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("remove_address is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -1187,11 +1204,11 @@ EXPORT_API int vpnsvc_add_route(vpnsvc_h handle, const char *route_address, int
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_add_route() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_add_route() failed");
                else
                        LOGD("vpn_add_route() succeed");
        }
@@ -1215,8 +1232,8 @@ EXPORT_API int vpnsvc_remove_route(vpnsvc_h handle, const char *route_address, i
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (route_address == NULL) {
-               LOGE("route_address is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("route_address is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -1230,11 +1247,11 @@ EXPORT_API int vpnsvc_remove_route(vpnsvc_h handle, const char *route_address, i
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_remove_route() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_remove_route() failed");
                else
                        LOGD("vpn_remove_route() succeed");
        }
@@ -1258,8 +1275,8 @@ EXPORT_API int vpnsvc_add_dns_server(vpnsvc_h handle, const char *dns_server)
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (dns_server == NULL) {
-               LOGE("dns_server is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("dns_server is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
 
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
@@ -1273,11 +1290,11 @@ EXPORT_API int vpnsvc_add_dns_server(vpnsvc_h handle, const char *dns_server)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_add_dns_server() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_add_dns_server() failed");
                else
                        LOGD("vpn_add_dns_server() succeed");
        }
@@ -1301,8 +1318,8 @@ EXPORT_API int vpnsvc_remove_dns_server(vpnsvc_h handle, const char *dns_server)
        tun_s = (vpnsvc_tun_s*)handle;
 
        if (dns_server == NULL) {
-               LOGE("dns_server is NULL"); //LCOV_EXCL_LINE
-               return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               LOGE("dns_server is NULL");
+               return VPNSVC_ERROR_INVALID_PARAMETER;
        }
        op = _vpnsvc_invoke_dbus_method(tun_s->connection,
                                                                NETCONFIG_SERVICE_NAME,
@@ -1315,11 +1332,11 @@ EXPORT_API int vpnsvc_remove_dns_server(vpnsvc_h handle, const char *dns_server)
                return VPNSVC_ERROR_PERMISSION_DENIED;
 
        if (op == NULL) {
-               return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
+               return VPNSVC_ERROR_IPC_FAILED;
        } else {
                g_variant_get(op, "(i)", &result);
                if (result != VPNSVC_ERROR_NONE)
-                       LOGE("vpn_remove_dns_server() failed"); //LCOV_EXCL_LINE
+                       LOGE("vpn_remove_dns_server() failed");
                else
                        LOGD("vpn_remove_dns_server() succeed");
        }
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..223386f
--- /dev/null
@@ -0,0 +1,28 @@
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+ADD_DEFINITIONS("-DVPN_SERVICE_GTEST")
+
+pkg_check_modules(gtest_pkgs REQUIRED gmock glib-2.0)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(VPN_SERVICE_GTEST "vpn-service-gtest")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-lto")
+
+FILE(GLOB GTEST_SRCS *.cpp mocks/*.c ${CMAKE_SOURCE_DIR}/src/*.c)
+ADD_EXECUTABLE(${VPN_SERVICE_GTEST} ${GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${VPN_SERVICE_GTEST} ${gtest_pkgs_LIBRARIES} ${${PACKAGE_NAME}_LIBRARIES})
+SET_TARGET_PROPERTIES(${VPN_SERVICE_GTEST} PROPERTIES
+       COMPILE_FLAGS "-fPIE"
+       LINK_FLAGS "-Wl,\
+--wrap=close,\
+--wrap=fcntl,\
+--wrap=fcntl64,\
+--wrap=open,\
+--wrap=open64,\
+--wrap=g_bus_get_sync,\
+--wrap=g_dbus_connection_call_sync,\
+--wrap=g_dbus_connection_call_with_unix_fd_list_sync,\
+--wrap=g_unix_fd_list_append,\
+--wrap=select,\
+--wrap=system_info_get_platform_bool,\
+--wrap=write")
diff --git a/tests/mocks/vpn_service_file.c b/tests/mocks/vpn_service_file.c
new file mode 100644 (file)
index 0000000..21dfdcf
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vpn_service_file.h"
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+
+#define VPN_TUN_PATH "/dev/net/tun"
+#define VPN_TUN_FD 1023
+
+static bool vpn_service_mock_file_result;
+
+extern int __real_open(const char *__path, int __oflag, ...);
+extern int __real_open64(const char *__path, int __oflag, ...);
+extern int __real_close(int fd);
+
+void vpn_service_mock_set_file_result(bool result)
+{
+       vpn_service_mock_file_result = result;
+}
+
+int __wrap_open(const char *pathname, int __oflag, ...)
+{
+       if (!vpn_service_mock_file_result)
+               return -1;
+
+       if (strcmp(pathname, VPN_TUN_PATH) == 0)
+               return VPN_TUN_FD;
+
+       return __real_open(pathname, __oflag);
+}
+
+int __wrap_open64(const char *pathname, int __oflag, ...)
+{
+       if (!vpn_service_mock_file_result)
+               return -1;
+
+       if (strcmp(pathname, VPN_TUN_PATH) == 0)
+               return VPN_TUN_FD;
+
+       if (strlen(pathname) > 5 && !strcmp(pathname + strlen(pathname) - 5, ".gcda")) {
+               va_list vl;
+               mode_t mode;
+
+               va_start(vl, __oflag);
+               mode = va_arg(vl, mode_t);
+               va_end(vl);
+
+               return __real_open64(pathname, __oflag, mode);
+       }
+
+       return __real_open64(pathname, __oflag);
+}
+
+int __wrap_close(int fd)
+{
+       if (fd == VPN_TUN_FD)
+               return 0;
+
+       return __real_close(fd);
+}
+
+int __wrap_fcntl(int fd, int cmd, ... /* arg */ )
+{
+       if (!vpn_service_mock_file_result)
+               return -1;
+
+       return 1;
+}
+
+int __wrap_fcntl64(int fd, int cmd, ... /* arg */ )
+{
+       if (!vpn_service_mock_file_result)
+               return -1;
+
+       return 1;
+}
diff --git a/tests/mocks/vpn_service_file.h b/tests/mocks/vpn_service_file.h
new file mode 100644 (file)
index 0000000..b5e5482
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+
+void vpn_service_mock_set_file_result(bool result);
diff --git a/tests/mocks/vpn_service_gdbus.c b/tests/mocks/vpn_service_gdbus.c
new file mode 100644 (file)
index 0000000..3633f2c
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vpn_service_gdbus.h"
+
+#include <stdbool.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <gio/gunixfdlist.h>
+
+static bool vpn_service_mock_gdbus_result;
+
+void vpn_service_mock_set_gdbus_result(bool value)
+{
+       vpn_service_mock_gdbus_result = value;
+}
+
+GDBusConnection *__wrap_g_bus_get_sync(GBusType bus_type, GCancellable *cancellable, GError **error)
+{
+    return (GDBusConnection *)g_object_new(G_TYPE_DBUS_CONNECTION, NULL);
+}
+
+GVariant *__wrap_g_dbus_connection_call_sync(GDBusConnection *connection,
+               const gchar             *bus_name,
+               const gchar             *object_path,
+               const gchar             *interface_name,
+               const gchar             *method_name,
+               GVariant                *parameters,
+               const GVariantType *reply_type,
+               GDBusCallFlags  flags,
+               gint                    timeout_msec,
+               GCancellable    *cancellable,
+               GError                  **error)
+{
+       GVariant *params = NULL;
+
+       if (!vpn_service_mock_gdbus_result) {
+               *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "dbus error");
+               return NULL;
+       }
+
+       if (strcmp(method_name, "vpn_up") == 0
+                       || strcmp(method_name, "vpn_down") == 0
+                       || strcmp(method_name, "vpn_block_networks") == 0
+                       || strcmp(method_name, "vpn_unblock_networks") == 0
+                       || strcmp(method_name, "vpn_update_settings") == 0
+                       || strcmp(method_name, "vpn_add_route") == 0
+                       || strcmp(method_name, "vpn_remove_route") == 0
+                       || strcmp(method_name, "vpn_add_dns_server") == 0
+                       || strcmp(method_name, "vpn_deinit") == 0
+                       || strcmp(method_name, "vpn_remove_dns_server") == 0)
+               params = g_variant_new("(i)", 0);
+
+       return params;
+}
+
+GVariant *__wrap_g_dbus_connection_call_with_unix_fd_list_sync(GDBusConnection *connection,
+               const gchar             *bus_name,
+               const gchar             *object_path,
+               const gchar             *interface_name,
+               const gchar             *method_name,
+               GVariant                *parameters,
+               const GVariantType      *reply_type,
+               GDBusCallFlags  flags,
+               gint                    timeout_msec,
+               GUnixFDList             *fd_list,
+               GUnixFDList             **out_fd_list,
+               GCancellable    *cancellable,
+               GError                  **error)
+{
+       GVariant *params = NULL;
+
+       if (!vpn_service_mock_gdbus_result) {
+               *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "dbus error");
+               return NULL;
+       }
+
+       if (strcmp(method_name, "vpn_init") == 0)
+               params = g_variant_new("(iis)", 0, 1, "tizen");
+       else if (strcmp(method_name, "vpn_protect") == 0)
+               params = g_variant_new("(i)", 0);
+
+       return params;
+}
+
+gint __wrap_g_unix_fd_list_append(GUnixFDList *list,
+               gint fd,
+               GError **error)
+{
+       *error = NULL;
+       return 0;
+}
diff --git a/tests/mocks/vpn_service_gdbus.h b/tests/mocks/vpn_service_gdbus.h
new file mode 100644 (file)
index 0000000..8ac8e19
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+
+void vpn_service_mock_set_gdbus_result(bool value);
diff --git a/tests/mocks/vpn_service_io.c b/tests/mocks/vpn_service_io.c
new file mode 100644 (file)
index 0000000..3bfb775
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vpn_service_io.h"
+
+#include <sys/select.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+static bool vpn_service_mock_io_result;
+static bool vpn_service_mock_io_timeout;
+
+void vpn_service_mock_set_io_result(bool result)
+{
+       vpn_service_mock_io_result = result;
+}
+
+void vpn_service_mock_set_io_timeout(bool timeout)
+{
+       vpn_service_mock_io_timeout = timeout;
+}
+
+int __wrap_select(int nfds, fd_set *readfds, fd_set *writefds,
+               fd_set *exceptfds, struct timeval *timeout)
+{
+       if (!vpn_service_mock_io_result && !vpn_service_mock_io_timeout)
+               return -1;
+
+       if (vpn_service_mock_io_timeout)
+               return 0;
+
+       return 1;
+}
+
+ssize_t __wrap_write(int fd, const void *buf, size_t count)
+{
+       if (!vpn_service_mock_io_result)
+               return -1;
+
+       return 0;
+}
diff --git a/tests/mocks/vpn_service_io.h b/tests/mocks/vpn_service_io.h
new file mode 100644 (file)
index 0000000..2766766
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+
+void vpn_service_mock_set_io_result(bool result);
+void vpn_service_mock_set_io_timeout(bool timeout);
diff --git a/tests/mocks/vpn_service_system_info.c b/tests/mocks/vpn_service_system_info.c
new file mode 100644 (file)
index 0000000..e9f2c0f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "vpn_service_system_info.h"
+
+#include <string.h>
+#include <stdbool.h>
+#include <system_info.h>
+
+static bool vpn_service_mock_sysinfo_result;
+
+void vpn_service_mock_set_sysinfo_result(bool value)
+{
+       vpn_service_mock_sysinfo_result = value;
+}
+
+int __wrap_system_info_get_platform_bool(const char *key, bool *value)
+{
+       *value = vpn_service_mock_sysinfo_result;
+       return SYSTEM_INFO_ERROR_NONE;
+}
diff --git a/tests/mocks/vpn_service_system_info.h b/tests/mocks/vpn_service_system_info.h
new file mode 100644 (file)
index 0000000..967c8c8
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+
+void vpn_service_mock_set_sysinfo_result(bool value);
diff --git a/tests/vpn-service-gtest-common.cpp b/tests/vpn-service-gtest-common.cpp
new file mode 100755 (executable)
index 0000000..424a381
--- /dev/null
@@ -0,0 +1,403 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <gtest/gtest.h>
+
+#include "vpn_service.h"
+
+extern "C" {
+#include "mocks/vpn_service_file.h"
+#include "mocks/vpn_service_system_info.h"
+#include "mocks/vpn_service_gdbus.h"
+#include "mocks/vpn_service_io.h"
+}
+
+class VpnServiceTest: public ::testing::Test {
+       protected:
+               vpnsvc_h handle;
+
+               void SetUp() override
+               {
+                       vpn_service_mock_set_file_result(true);
+                       vpn_service_mock_set_sysinfo_result(true);
+                       vpn_service_mock_set_gdbus_result(true);
+                       vpn_service_mock_set_io_result(true);
+                       vpn_service_mock_set_io_timeout(false);
+                       vpnsvc_init("tizen", &handle);
+               }
+
+               void TearDown() override
+               {
+                       vpnsvc_deinit(handle);
+                       vpn_service_mock_set_gdbus_result(true);
+                       vpn_service_mock_set_sysinfo_result(true);
+                       vpn_service_mock_set_io_result(true);
+                       vpn_service_mock_set_file_result(true);
+               }
+};
+
+TEST_F(VpnServiceTest, InitN)
+{
+       vpnsvc_h test_handle = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_init("tizen", NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_init(NULL, &test_handle));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_init(NULL, NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_init("tizen", &test_handle));
+
+       vpn_service_mock_set_gdbus_result(true);
+       vpn_service_mock_set_file_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IO_ERROR, vpnsvc_init("tizen", &test_handle));
+}
+
+TEST_F(VpnServiceTest, InitP)
+{
+       vpnsvc_h test_handle = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_init("tizen", &test_handle));
+
+       vpnsvc_deinit(test_handle);
+}
+
+TEST_F(VpnServiceTest, DeinitN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_deinit(NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_deinit(handle));
+       vpn_service_mock_set_gdbus_result(true);
+}
+
+TEST_F(VpnServiceTest, DeinitP)
+{
+       vpnsvc_h test_handle = NULL;
+
+       vpnsvc_init("tizen", &test_handle);
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_deinit(test_handle));
+}
+
+TEST_F(VpnServiceTest, ProtectN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_protect(NULL, 1, "tun0"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_protect(handle, -1, "tun0"));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_protect(handle, 1, "tun0"));
+
+       vpn_service_mock_set_gdbus_result(true);
+}
+
+TEST_F(VpnServiceTest, ProtectP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_protect(handle, 1, "tun0"));
+}
+
+TEST_F(VpnServiceTest, ReadN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_read(NULL, 1000));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_read(handle, -1));
+
+       vpn_service_mock_set_io_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IO_ERROR, vpnsvc_read(handle, 100));
+
+       vpn_service_mock_set_io_timeout(true);
+       EXPECT_EQ(VPNSVC_ERROR_TIMEOUT, vpnsvc_read(handle, 100));
+}
+
+TEST_F(VpnServiceTest, ReadP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_read(handle, 100));
+}
+
+TEST_F(VpnServiceTest, WriteN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_write(NULL, NULL, -1));
+
+       // TODO: Add new testcase for failure of write()
+}
+
+TEST_F(VpnServiceTest, WriteP)
+{
+       char test_data[14] = "This is test.";
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_write(handle, test_data, 5));
+}
+
+TEST_F(VpnServiceTest, BlockNetworksN)
+{
+       char *dest_vpn_addr[2] = {"125.209.222.141", "180.70.134.19"};
+       char *dest_addr[2] = {"216.58.221.142", "206.190.36.45"};
+       int vpn_prefix[2] = {32, 32};
+       int prefix[2] = {32, 32};
+       size_t num_allow_vpn_routes = 2;
+       size_t num_allow_routes = 2;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_block_networks(NULL,
+                               NULL, NULL, 0, NULL, NULL, 0));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_block_networks(handle,
+                               NULL, NULL, 256, NULL, NULL, 256));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_block_networks(handle,
+                               dest_vpn_addr, vpn_prefix, num_allow_vpn_routes,
+                               dest_addr, prefix, num_allow_routes));
+}
+
+TEST_F(VpnServiceTest, BlockNetworksP)
+{
+       char *dest_vpn_addr[2] = {"125.209.222.141", "180.70.134.19"};
+       char *dest_addr[2] = {"216.58.221.142", "206.190.36.45"};
+       int vpn_prefix[2] = {32, 32};
+       int prefix[2] = {32, 32};
+       size_t num_allow_vpn_routes = 2;
+       size_t num_allow_routes = 2;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_block_networks(handle,
+                               dest_vpn_addr, vpn_prefix, num_allow_vpn_routes,
+                               dest_addr, prefix, num_allow_routes));
+}
+
+TEST_F(VpnServiceTest, UnBlockNetworksN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_unblock_networks(NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_unblock_networks(handle));
+}
+
+TEST_F(VpnServiceTest, UnBlockNetworksP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_unblock_networks(handle));
+}
+
+TEST_F(VpnServiceTest, UpdateSettingsN)
+{
+       char local_ip[16] = "192.168.0.123";
+       char remote_ip[16] = "157.54.0.1";
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_update_settings(NULL));
+
+       // local_ip isn't set
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_update_settings(handle));
+
+       // remote_ip isn't set
+       vpnsvc_set_local_ip_address(handle, local_ip);
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_update_settings(handle));
+
+       vpn_service_mock_set_gdbus_result(false);
+       vpnsvc_set_remote_ip_address(handle, remote_ip);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_update_settings(handle));
+}
+
+TEST_F(VpnServiceTest, UpdateSettingsP)
+{
+       char local_ip[16] = "192.168.0.123";
+       char remote_ip[16] = "157.54.0.1";
+
+       vpnsvc_set_local_ip_address(handle, local_ip);
+       vpnsvc_set_remote_ip_address(handle, remote_ip);
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_update_settings(handle));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceFdN)
+{
+       int fd = 0;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_fd(NULL, &fd));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_fd(handle, NULL));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceFdP)
+{
+       int fd = 0;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_get_iface_fd(handle, &fd));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceIndexN)
+{
+       int index = 0;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_index(NULL, &index));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_index(handle, NULL));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceIndexP)
+{
+       int index = 0;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_get_iface_index(handle, &index));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceNameN)
+{
+       char *name = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_name(NULL, &name));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_iface_name(handle, NULL));
+}
+
+TEST_F(VpnServiceTest, GetInterfaceNameP)
+{
+       char *name = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_get_iface_name(handle, &name));
+       free(name);
+}
+
+TEST_F(VpnServiceTest, SetMtuN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_mtu(NULL, 1500));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_mtu(handle, 0));
+}
+
+TEST_F(VpnServiceTest, SetMtuP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_mtu(handle, 1500));
+}
+
+TEST_F(VpnServiceTest, SetBlockingN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_blocking(NULL, false));
+}
+
+TEST_F(VpnServiceTest, SetBlockingP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_blocking(handle, false));
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_blocking(handle, true));
+}
+
+TEST_F(VpnServiceTest, SetSessionN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_session(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_session(NULL, "VPN session"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_session(NULL, NULL));
+
+       char long_name[33];
+       for (int i = 0; i < 33; i++)
+               long_name[i] = 'a';
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_session(handle, long_name));
+}
+
+TEST_F(VpnServiceTest, SetSessionP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_session(handle, "VPN session"));
+}
+
+TEST_F(VpnServiceTest, GetSessionN)
+{
+       char *session = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_session(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_session(NULL, &session));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_get_session(NULL, NULL));
+}
+
+TEST_F(VpnServiceTest, GetSessionP)
+{
+       char *session = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_get_session(handle, &session));
+       free(session);
+}
+
+TEST_F(VpnServiceTest, SetLocalIpAddressN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_local_ip_address(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_local_ip_address(NULL, "192.168.0.123"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_local_ip_address(NULL, NULL));
+}
+
+TEST_F(VpnServiceTest, SetLocalIpAddressP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_local_ip_address(handle, "192.168.0.123"));
+}
+
+TEST_F(VpnServiceTest, SetRemoteIpAddressN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_remote_ip_address(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_remote_ip_address(NULL, "157.54.0.1"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_remote_ip_address(NULL, NULL));
+}
+
+TEST_F(VpnServiceTest, SetRemoteIpAddressP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_local_ip_address(handle, "157.54.0.1"));
+}
+
+TEST_F(VpnServiceTest, AddRouteN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_route(handle, NULL, 24));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_route(NULL, "192.168.0.1", 24));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_route(NULL, NULL, 24));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_add_route(handle, "192.168.0.1", 24));
+}
+
+TEST_F(VpnServiceTest, AddRouteP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_add_route(handle, "192.168.0.1", 24));
+}
+
+TEST_F(VpnServiceTest, RemoveRouteN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_route(handle, NULL, 24));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_route(NULL, "192.168.0.1", 24));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_route(NULL, NULL, 24));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_remove_route(handle, "192.168.0.1", 24));
+}
+
+TEST_F(VpnServiceTest, RemoveRouteP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_remove_route(handle, "192.168.0.1", 24));
+}
+
+TEST_F(VpnServiceTest, AddDnsServerN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_dns_server(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_dns_server(NULL, "8.8.4.4"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_add_dns_server(NULL, NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_add_dns_server(handle, "8.8.4.4"));
+}
+
+TEST_F(VpnServiceTest, AddDnsServerP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_add_dns_server(handle, "8.8.4.4"));
+}
+
+TEST_F(VpnServiceTest, RemoveDnsServerN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_dns_server(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_dns_server(NULL, "8.8.4.4"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_remove_dns_server(NULL, NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_remove_dns_server(handle, "8.8.4.4"));
+}
+
+TEST_F(VpnServiceTest, RemoveDnsServerP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_remove_dns_server(handle, "8.8.4.4"));
+}
diff --git a/tests/vpn-service-gtest-internal.cpp b/tests/vpn-service-gtest-internal.cpp
new file mode 100755 (executable)
index 0000000..986757d
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <gtest/gtest.h>
+
+#include "vpn_service.h"
+#include "vpn_service_internal.h"
+
+extern "C" {
+#include "mocks/vpn_service_file.h"
+#include "mocks/vpn_service_system_info.h"
+#include "mocks/vpn_service_gdbus.h"
+}
+
+class VpnServiceTest: public ::testing::Test {
+       protected:
+               vpnsvc_h handle;
+
+               void SetUp() override
+               {
+                       vpn_service_mock_set_file_result(true);
+                       vpn_service_mock_set_sysinfo_result(true);
+                       vpn_service_mock_set_gdbus_result(true);
+                       vpnsvc_create(&handle);
+               }
+
+               void TearDown() override
+               {
+                       vpnsvc_destroy(handle);
+                       vpn_service_mock_set_gdbus_result(true);
+                       vpn_service_mock_set_sysinfo_result(true);
+                       vpn_service_mock_set_file_result(true);
+               }
+};
+
+TEST_F(VpnServiceTest, CreateHandleN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_create(NULL));
+}
+
+TEST_F(VpnServiceTest, CreateHandleP)
+{
+       vpnsvc_h test_handle = NULL;
+
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_create(&test_handle));
+
+       vpnsvc_destroy(test_handle);
+}
+
+TEST_F(VpnServiceTest, DestroyHandleN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_destroy(NULL));
+}
+
+TEST_F(VpnServiceTest, DestroyHandleP)
+{
+       vpnsvc_h test_handle = NULL;
+
+       vpnsvc_create(&test_handle);
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_destroy(test_handle));
+}
+
+TEST_F(VpnServiceTest, SetInterfaceNameN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_iface_name(NULL, "tizen"));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_iface_name(handle, NULL));
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_set_iface_name(NULL, NULL));
+}
+
+TEST_F(VpnServiceTest, SetInterfaceNameP)
+{
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_set_iface_name(handle, "tizen"));
+}
+
+TEST_F(VpnServiceTest, InterfaceUpN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_up(NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       vpnsvc_set_iface_name(handle, "tizen");
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_up(handle));
+}
+
+TEST_F(VpnServiceTest, InterfaceUpP)
+{
+       vpnsvc_set_iface_name(handle, "tizen");
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_up(handle));
+}
+
+TEST_F(VpnServiceTest, InterfaceDownN)
+{
+       EXPECT_EQ(VPNSVC_ERROR_INVALID_PARAMETER, vpnsvc_up(NULL));
+
+       vpn_service_mock_set_gdbus_result(false);
+       vpnsvc_set_iface_name(handle, "tizen");
+       EXPECT_EQ(VPNSVC_ERROR_IPC_FAILED, vpnsvc_down(handle));
+}
+
+TEST_F(VpnServiceTest, InterfaceDownP)
+{
+       vpnsvc_set_iface_name(handle, "tizen");
+       EXPECT_EQ(VPNSVC_ERROR_NONE, vpnsvc_down(handle));
+}
diff --git a/tests/vpn-service-gtest-main.cpp b/tests/vpn-service-gtest-main.cpp
new file mode 100755 (executable)
index 0000000..4890e9c
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv)
+{
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
similarity index 99%
rename from test/CMakeLists.txt
rename to tools/CMakeLists.txt
index 36abda3..d9f6c77 100755 (executable)
@@ -16,7 +16,6 @@ SET(pc_requires "capi-base-common")
 SET(TEST_SRCS
        vpn_service_test.c)
 
-
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
 INCLUDE(FindPkgConfig)