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)
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
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
%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)
%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}
%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
%{_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/*
{
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;
}
}
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));
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;
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,
&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;
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,
&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;
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;
/* 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;
/* 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);
}
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 */
/* 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;
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");
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,
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");
}
/* 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);
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");
}
/* 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,
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");
}
/* 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 */
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;
/* 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);
/* 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) {
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]);
/* 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]);
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");
}
/* 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,
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");
}
/* 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;
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");
}
/* 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);
/* 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);
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);
/* 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);
/* 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;
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;
}
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;
}
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);
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;
}
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);
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,
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");
}
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,
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");
}
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,
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");
}
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,
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");
}
--- /dev/null
+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")
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+* 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);
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
--- /dev/null
+/*
+* 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;
+}
--- /dev/null
+/*
+* 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);
--- /dev/null
+/*
+* 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"));
+}
--- /dev/null
+/*
+* 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));
+}
--- /dev/null
+/*
+* 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();
+}
SET(TEST_SRCS
vpn_service_test.c)
-
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE(FindPkgConfig)