)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tools)
+ADD_SUBDIRECTORY(tests)
IF(UNIX)
BuildRequires: pkgconfig(key-manager)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(gmock)
BuildRequires: cmake
%if 0%{?gcov:1}
BuildRequires: lcov
+BuildRequires: tar
%endif
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
make %{?_smp_mflags}
+%install
+%make_install
+
%if 0%{?gcov:1}
-mkdir -p gcov-obj
-find . -name '*.gcno' ! -iname "*client*" ! -name "*test*" -exec cp '{}' 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
-%install
-%make_install
-%make_install
+%check
+tests/tethering-gtest
+
%if 0%{?gcov:1}
-mkdir -p %{buildroot}%{_datadir}/gcov/obj
-install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
%endif
%post -p /sbin/ldconfig
static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
{
if (conn == NULL || signal_name == NULL)
- return; //LCOV_EXCL_LINE
+ return;
GVariant *message = NULL;
GError *error = NULL;
g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH,
TETHERING_SERVICE_INTERFACE, signal_name, message, &error);
if (error) {
- ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); //LCOV_EXCL_LINE
- g_error_free(error); //LCOV_EXCL_LINE
+ ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message);
+ g_error_free(error);
}
}
security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK &&
security_type != TETHERING_WIFI_SECURITY_TYPE_WPS &&
security_type != TETHERING_WIFI_SECURITY_TYPE_SAE) {
- ERR("Invalid param\n"); //LCOV_EXCL_LINE
+ ERR("Invalid param\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) {
- ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
+ ERR("vconf_set_int is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type)
{
if (security_type == NULL) {
- ERR("Invalid param\n"); //LCOV_EXCL_LINE
+ ERR("Invalid param\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY,
(int *)security_type) < 0) {
- ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
+ ERR("vconf_get_int is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
static tethering_error_e __set_visible(const bool visible)
{
if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) {
- ERR("vconf_set_int is failed\n"); //LCOV_EXCL_LINE
+ ERR("vconf_set_int is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
static tethering_error_e __get_visible(bool *visible)
{
if (visible == NULL) {
- ERR("Invalid param\n"); //LCOV_EXCL_LINE
+ ERR("Invalid param\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
int hide = 0;
if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) {
- ERR("vconf_get_int is failed\n"); //LCOV_EXCL_LINE
+ ERR("vconf_get_int is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
err = TETHERING_ERROR_NONE;
break;
- //LCOV_EXCL_START
case MOBILE_AP_ERROR_RESOURCE:
err = TETHERING_ERROR_OUT_OF_MEMORY;
break;
- //LCOV_EXCL_STOP
case MOBILE_AP_ERROR_INTERNAL:
err = TETHERING_ERROR_OPERATION_FAILED;
err = TETHERING_ERROR_INVALID_PARAMETER;
break;
- //LCOV_EXCL_START
case MOBILE_AP_ERROR_ALREADY_ENABLED:
err = TETHERING_ERROR_OPERATION_FAILED;
break;
case MOBILE_AP_ERROR_PERMISSION_DENIED:
err = TETHERING_ERROR_PERMISSION_DENIED;
break;
- //LCOV_EXCL_STOP
default:
ERR("Not defined error : %d\n", agent_error);
err = TETHERING_ERROR_OPERATION_FAILED;
return err;
}
-//LCOV_EXCL_START
static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
DBG("-\n");
}
-//LCOV_EXCL_STOP
static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
DBG("-\n");
}
-//LCOV_EXCL_START
static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
g_free(buf);
DBG("-\n");
}
-//LCOV_EXCL_STOP
static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
DBG("-\n");
}
-//LCOV_EXCL_START
static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
}
DBG("-\n");
}
-//LCOV_EXCL_STOP
static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_SAE_STR) == 0)
security_type = TETHERING_WIFI_SECURITY_TYPE_SAE;
else {
- SERR("Unknown type : %s\n", buf); //LCOV_EXCL_LINE
+ SERR("Unknown type : %s\n", buf);
g_free(buf);
return;
}
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
{
- DBG("+\n"); //LCOV_EXCL_LINE
+ DBG("+\n");
_retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
__tethering_h *th = (__tethering_h *)user_data;
scb = th->ssid_visibility_changed_cb;
if (scb == NULL) {
- DBG("-\n"); //LCOV_EXCL_LINE
+ DBG("-\n");
return;
}
g_variant_get(parameters, "(s)", &buf);
scb(visible, data);
g_free(buf);
- DBG("-\n"); //LCOV_EXCL_LINE
+ DBG("-\n");
}
static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
GVariant *parameters, gpointer user_data)
{
- DBG("+\n"); //LCOV_EXCL_LINE
+ DBG("+\n");
_retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
__tethering_h *th = (__tethering_h *)user_data;
data = th->passphrase_user_data;
pcb(data);
- DBG("-\n"); //LCOV_EXCL_LINE
+ DBG("-\n");
}
static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
- INFO("+\n"); //LCOV_EXCL_LINE
+ INFO("+\n");
_retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
GError *g_error = NULL;
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
- //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
++retry < TETHERING_ERROR_RECOVERY_MAX) {
else
error = TETHERING_ERROR_OPERATION_FAILED;
g_error_free(g_error);
- //LCOV_EXCL_STOP
} else {
g_variant_get(g_var, "(u)", &info);
error = __get_error(info);
}
retry = 0;
- INFO("cfm event : wifi tethering enable info : %d\n", error); //LCOV_EXCL_LINE
+ INFO("cfm event : wifi tethering enable info : %d\n", error);
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name,
sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL);
if (!ecb) {
- INFO("-\n"); //LCOV_EXCL_LINE
+ INFO("-\n");
return;
}
ecb(error, TETHERING_TYPE_WIFI, true, data);
g_variant_unref(g_var);
- INFO("-\n"); //LCOV_EXCL_LINE
+ INFO("-\n");
}
static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
- DBG("+\n"); //LCOV_EXCL_LINE
+ DBG("+\n");
_retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
GError *g_error = NULL;
GVariant *g_var;
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
- //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_NO_REPLY &&
++retry < TETHERING_ERROR_RECOVERY_MAX) {
else
error = TETHERING_ERROR_OPERATION_FAILED;
g_error_free(g_error);
- //LCOV_EXCL_STOP
} else {
g_variant_get(g_var, "(u)", &info);
g_variant_unref(g_var);
sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL);
if (!ecb) {
- DBG("-\n"); //LCOV_EXCL_LINE
+ DBG("-\n");
return;
}
DBG("-\n");
}
-//LCOV_EXCL_START
static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
ecb(error, TETHERING_TYPE_P2P, true, data);
DBG("-\n");
}
-//LCOV_EXCL_STOP
static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
- INFO("+\n"); //LCOV_EXCL_LINE
+ INFO("+\n");
_retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
GError *g_error = NULL;
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
- //LCOV_EXCL_START
ERR("DBus error [%s]\n", g_error->message);
g_error_free(g_error);
return;
- //LCOV_EXCL_STOP
}
g_variant_get(g_var, "(uu)", &event_type, &info);
INFO("cfm event : %d info : %d\n", event_type, info);
dcb(error, type, code, data);
break;
- //LCOV_EXCL_START
case MOBILE_AP_DISABLE_USB_TETHERING_CFM:
sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus,
NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name,
default:
ERR("Invalid event\n");
break;
- //LCOV_EXCL_STOP
}
- INFO("-\n"); //LCOV_EXCL_LINE
+ INFO("-\n");
}
static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res,
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
- //LCOV_EXCL_START
ERR("DBus fail [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
tethering_error = TETHERING_ERROR_OPERATION_FAILED;
flag = true;
- //LCOV_EXCL_STOP
}
if (th->data_usage_cb == NULL) {
- ERR("There is no data_usage_cb\n"); //LCOV_EXCL_LINE
+ ERR("There is no data_usage_cb\n");
return;
}
if (flag) {
g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error);
if (g_error) {
- ERR("DBus fail [%s]\n", g_error->message); //LCOV_EXCL_LINE
+ ERR("DBus fail [%s]\n", g_error->message);
if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
tethering_error = TETHERING_ERROR_PERMISSION_DENIED;
else
_retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
switch (type) {
- //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_strlcpy(buf, TETHERING_USB_IF, len);
break;
- //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI:
g_strlcpy(buf, TETHERING_WIFI_IF, len);
break;
-
case TETHERING_TYPE_BT:
g_strlcpy(buf, TETHERING_BT_IF, len);
break;
-
- //LCOV_EXCL_START
default:
ERR("Not supported type : %d\n", type);
return false;
- //LCOV_EXCL_STOP
}
return true;
}
_retvm_if(buf == NULL, false, "parameter(buf) is NULL\n");
switch (type) {
- //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_strlcpy(buf, TETHERING_USB_GATEWAY, len);
break;
- //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI:
g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len);
break;
-
case TETHERING_TYPE_BT:
g_strlcpy(buf, TETHERING_BT_GATEWAY, len);
break;
- //LCOV_EXCL_START
default:
ERR("Not supported type : %d\n", type);
return false;
- //LCOV_EXCL_STOP
}
return true;
}
static int __get_common_ssid(char *ssid, unsigned int size)
{
if (ssid == NULL) {
- ERR("ssid is null\n"); //LCOV_EXCL_LINE
+ ERR("ssid is null\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
char *ptr = NULL;
if (th == NULL || set == NULL) {
- ERR("null parameter\n-\n"); //LCOV_EXCL_LINE
+ ERR("null parameter\n-\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return ret;
- //LCOV_EXCL_STOP
}
if (parameters != NULL) {
if (__generate_initial_passphrase(th->passphrase,
sizeof(th->passphrase)) == 0) {
- //LCOV_EXCL_START
ERR("random passphrase generation failed\n");
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) {
- //LCOV_EXCL_START
ERR("common ssid get failed\n");
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
#if !GLIB_CHECK_VERSION(2, 36, 0)
GCancellable *cancellable = g_cancellable_new();
th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error);
if (error) {
- //LCOV_EXCL_START
ERR("Couldn't connect to the System bus[%s]", error->message);
g_error_free(error);
g_cancellable_cancel(cancellable);
g_object_unref(cancellable);
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
th->cancellable = cancellable;
NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH,
TETHERING_SERVICE_INTERFACE, th->cancellable, &error);
if (!th->client_bus_proxy) {
- //LCOV_EXCL_START
if (error)
ERR("Couldn't create the proxy object because of %s\n", error->message);
g_cancellable_cancel(th->cancellable);
g_object_unref(th->client_bus);
free(th);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
__connect_signals((tethering_h)th);
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
if (__check_precondition(type) == FALSE) {
- //LCOV_EXCL_START
INFO("-\n");
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
switch (type) {
- //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_USB_TETHER_ON].sig_id);
G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
(GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering);
break;
- //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI: {
_softap_settings_t set = {"", "", "", 0, false};
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
- //LCOV_EXCL_START
ERR("softap settings initialization failed\n");
DBG("-\n");
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id);
break;
- //LCOV_EXCL_START
case TETHERING_TYPE_P2P: {
_softap_settings_t p2p_set = {"", "", "", 0, false};
ret = __prepare_wifi_settings(tethering, &p2p_set);
DBG("-\n");
return TETHERING_ERROR_INVALID_PARAMETER;
}
- //LCOV_EXCL_STOP
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
INFO("-\n");
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
if (__check_precondition(type) == FALSE) {
- //LCOV_EXCL_START
DBG("-\n");
g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
switch (type) {
GDBusConnection *connection = th->client_bus;
switch (type) {
- //LCOV_EXCL_START
case TETHERING_TYPE_USB:
g_dbus_connection_signal_unsubscribe(connection,
sigs[E_SIGNAL_USB_TETHER_OFF].sig_id);
(GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
break;
- //LCOV_EXCL_STOP
case TETHERING_TYPE_WIFI:
(GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
break;
- //LCOV_EXCL_START
case TETHERING_TYPE_P2P:
g_dbus_proxy_call(proxy, "disable_p2p_tethering",
NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
ERR("Not supported tethering type [%d]\n", type);
DBG("-\n");
return TETHERING_ERROR_INVALID_PARAMETER;
- //LCOV_EXCL_STOP
}
INFO("-\n");
return TETHERING_ERROR_NONE;
API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
- if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
+ if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
- else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
+ else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
_retvm_if(tethering_is_enabled(tethering, type) == false,
TETHERING_ERROR_NOT_ENABLED,
_retvm_if(s < 0, TETHERING_ERROR_OPERATION_FAILED,
"getting socket is failed\n");
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
- //LCOV_EXCL_START
ERR("getting mac is failed\n");
close(s);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
close(s);
API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
- if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); //LCOV_EXCL_LINE
+ if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE);
else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
- else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); //LCOV_EXCL_LINE
+ else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE);
_retvm_if(tethering_is_enabled(tethering, type) == false,
TETHERING_ERROR_NOT_ENABLED,
result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info",
NULL, G_DBUS_CALL_FLAGS_NONE,
-1, th->cancellable, &error);
- if (error)
- ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message); //LCOV_EXCL_LINE
+
+ if (error) {
+ ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+ g_error_free(error);
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+
g_variant_get(result, "(a(a{sv}))", &outer_iter);
- //LCOV_EXCL_START
while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
g_variant_get(station, "a{sv}", &inner_iter);
while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
g_free(client.hostname);
client.hostname = NULL;
g_variant_iter_free(outer_iter);
- g_variant_unref(station);
g_variant_unref(result);
DBG("-\n");
return TETHERING_ERROR_OPERATION_FAILED;
g_free(client.hostname);
client.hostname = NULL;
}
- //LCOV_EXCL_STOP
g_variant_iter_free(outer_iter);
- g_variant_unref(station);
g_variant_unref(result);
DBG("-\n");
return TETHERING_ERROR_NONE;
ret = __set_security_type(type);
if (ret == TETHERING_ERROR_NONE) {
-
switch (type) {
case TETHERING_WIFI_SECURITY_TYPE_NONE:
sec_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR;
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
_retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(type) is NULL\n");
}
if (*ssid == NULL) {
- ERR("strdup is failed\n"); //LCOV_EXCL_LINE
+ ERR("strdup is failed\n");
return TETHERING_ERROR_OUT_OF_MEMORY;
}
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
_retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(visible) is NULL\n");
g_variant_new("(s)", passphrase), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return ret;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &ret);
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return ret;
- //LCOV_EXCL_STOP
}
if (parameters != NULL) {
DBG("+\n");
if (th->settings_reloaded_cb) {
- ERR("Operation in progress\n"); //LCOV_EXCL_LINE
+ ERR("Operation in progress\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
ret = __prepare_wifi_settings(tethering, &set);
if (ret != TETHERING_ERROR_NONE) {
- ERR("softap settings initialization failed\n"); //LCOV_EXCL_LINE
+ ERR("softap settings initialization failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
fp = fopen(filepath, "a+");
if (!fp) {
- ERR("fopen is failed\n"); //LCOV_EXCL_LINE
+ ERR("fopen is failed\n");
return TETHERING_ERROR_OPERATION_FAILED;
}
while (fgets(line, MAX_BUF_SIZE, fp) != NULL) {
if (strncmp(mac, line, 17) == 0) {
- DBG("MAC %s already exist in the list\n", mac); //LCOV_EXCL_LINE
+ DBG("MAC %s already exist in the list\n", mac);
mac_exist = true;
break;
}
if (!mac_exist) {
p_mac = strdup(mac);
if (p_mac == NULL) {
- ERR("strdup failed\n"); //LCOV_EXCL_LINE
+ ERR("strdup failed\n");
fclose(fp);
return TETHERING_ERROR_OUT_OF_MEMORY;
}
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
result = TETHERING_ERROR_PERMISSION_DENIED;
th->dhcp_enabled = false;
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
g_variant_new("(ss)", rangestart, rangestop),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
th->dhcp_enabled = false;
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
G_DBUS_CALL_FLAGS_NONE,
-1, th->cancellable, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
g_clear_error(&error);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
return TETHERING_ERROR_NONE;
}
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL\n");
+ _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(txpower) is NULL\n");
_retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
TETHERING_ERROR_NOT_ENABLED,
"tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
g_variant_get(result, "(u)", txpower);
g_variant_unref(result);
} else {
- //LCOV_EXCL_START
if (error)
ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
g_clear_error(&error);
return TETHERING_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
}
g_clear_error(&error);
return TETHERING_ERROR_NONE;
g_variant_new("(u)", mtu),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
g_variant_new("(s)", mac),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
g_variant_new("(b)", enable),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL\n");
+ _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(ifname) is NULL\n");
_retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(protocol) is NULL\n");
+ _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(org_ip) is NULL\n");
+ _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(final_ip) is NULL\n");
GVariant *parameters;
GError *error = NULL;
g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
list = strdup(cmd);
if (list == NULL) {
- ERR("strdup failed\n"); //LCOV_EXCL_LINE
+ ERR("strdup failed\n");
return TETHERING_ERROR_OUT_OF_MEMORY;
}
parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
return TETHERING_ERROR_NONE;
}
-API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool* forwarding_enabled)
+API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
g_variant_new("(b)", enable),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
g_variant_new("(isb)", port, protocol, allow),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
if (ret == -1 || list == NULL) {
- ERR("asprintf failed\n"); //LCOV_EXCL_LINE
+ ERR("asprintf failed\n");
return TETHERING_ERROR_OUT_OF_MEMORY;
}
g_variant_new("(iisb)", port1, port2, protocol, allow),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
if (ret == -1 || list == NULL) {
- ERR("asprintf failed\n"); //LCOV_EXCL_LINE
+ ERR("asprintf failed\n");
return TETHERING_ERROR_OUT_OF_MEMORY;
}
return TETHERING_ERROR_NONE;
}
-API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool* filtering_enabled)
+API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
{
CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
g_variant_new("(ib)", type, enable),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return result;
- //LCOV_EXCL_STOP
}
g_variant_get(parameters, "(u)", &result);
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return ret;
- //LCOV_EXCL_STOP
}
if (parameters != NULL) {
_retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"parameter(tethering) is NULL");
+ _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(wps_pin) is NULL");
+
__tethering_h *th = (__tethering_h *)tethering;
GDBusProxy *proxy = th->client_bus_proxy;
GVariant *parameters = NULL;
g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {
- //LCOV_EXCL_START
ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
g_error_free(error);
return ret;
- //LCOV_EXCL_STOP
}
if (parameters != NULL) {
_retvm_if(dest == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"Parameter(dest) is NULL\n");
+ _retvm_if(origin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "Parameter(origin) is NULL\n");
__tethering_client_h *si = NULL;
__tethering_client_h *source = NULL;
_retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
"Parameter(client) is NULL\n");
+ _retvm_if(timestamp == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "Parameter(timestamp) is NULL\n");
+
__tethering_client_h *si = (__tethering_client_h *)client;
{
if (!is_feature_checked[feature]) {
if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
- //LCOV_EXCL_START
ERR("Get feature is failed");
return false;
- //LCOV_EXCL_STOP
}
is_feature_checked[feature] = true;
}
if (!supported) {
- //LCOV_EXCL_START
ERR("Not supported feature");
set_last_result(TETHERING_ERROR_NOT_SUPPORT_API);
va_end(list);
return TETHERING_ERROR_NOT_SUPPORT_API;
- //LCOV_EXCL_STOP
}
va_end(list);
set_last_result(TETHERING_ERROR_NONE);
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+ADD_DEFINITIONS("-DTETHERING_GTEST")
+
+pkg_check_modules(gtest_pkgs REQUIRED gmock glib-2.0)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(TETHERING_GTEST "tethering-gtest")
+FILE(GLOB GTEST_SRCS *.cpp mocks/*.c ${CMAKE_SOURCE_DIR}/src/*.c)
+ADD_EXECUTABLE(${TETHERING_GTEST} ${GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${TETHERING_GTEST} ${gtest_pkgs_LIBRARIES} ${${fw_name}_LIBRARIES})
+SET_TARGET_PROPERTIES(${TETHERING_GTEST} PROPERTIES
+ COMPILE_FLAGS "-fPIE"
+ LINK_FLAGS "-Wl,\
+--wrap=fopen,\
+--wrap=fopen64,\
+--wrap=calloc,\
+--wrap=malloc,\
+--wrap=g_cancellable_new,\
+--wrap=g_bus_get_sync,\
+--wrap=g_dbus_connection_signal_subscribe,\
+--wrap=g_dbus_connection_signal_unsubscribe,\
+--wrap=g_dbus_proxy_call,\
+--wrap=g_dbus_proxy_call_finish,\
+--wrap=g_dbus_proxy_call_sync,\
+--wrap=g_dbus_proxy_new_sync,\
+--wrap=g_dbus_proxy_set_default_timeout,\
+--wrap=g_dbus_connection_emit_signal,\
+--wrap=ioctl,\
+--wrap=rename,\
+--wrap=system_info_get_platform_bool,\
+--wrap=vconf_get_int,\
+--wrap=vconf_set_int,\
+--wrap=vconf_get_str")
--- /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 "tethering_dummy_client.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define TETHERING_STR_INFO_LEN 40
+
+typedef struct {
+ int interface;
+ char ip[TETHERING_STR_INFO_LEN];
+ char mac[TETHERING_STR_INFO_LEN];
+ char *hostname;
+ time_t tm;
+} __tethering_client_h;
+
+void tethering_mock_create_dummy_client(void **dummy_client)
+{
+ __tethering_client_h *client = NULL;
+
+ client = malloc(sizeof(__tethering_client_h));
+
+ client->interface = 2; // wifi
+ snprintf(client->ip, TETHERING_STR_INFO_LEN - 1, "%s", "192.168.43.125");
+ snprintf(client->mac, TETHERING_STR_INFO_LEN - 1, "%s", "AB:CD:EF:AB:CD:EF");
+ client->hostname = strdup("tethering-gtest");
+ time(&client->tm);
+
+ *dummy_client = (void *)client;
+}
+
+void tethering_mock_destroy_dummy_client(void *dummy_client)
+{
+ __tethering_client_h *client = (__tethering_client_h *)dummy_client;
+
+ if (!client)
+ return;
+
+ free(client->hostname);
+ free(client);
+}
--- /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
+
+void tethering_mock_create_dummy_client(void **dummy_client);
+void tethering_mock_destroy_dummy_client(void *dummy_client);
--- /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 "tethering_file.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#define TETHERING_TEST_FILE_PATH "/lib/hostapd/"
+#define TETHERING_TEST_FILE_PATH_LEN 13
+
+static bool tethering_mock_file_result;
+
+extern FILE *__real_fopen(const char *pathname, const char *mode);
+extern int __real_rename(const char *old, const char *new);
+
+void tethering_mock_set_file_result(bool result)
+{
+ tethering_mock_file_result = result;
+}
+
+FILE *__wrap_fopen(const char *pathname, const char *mode)
+{
+ if (!tethering_mock_file_result)
+ return NULL;
+
+ char *ptr = strstr(pathname, TETHERING_TEST_FILE_PATH);
+
+ if (!ptr)
+ return __real_fopen(pathname, mode);
+
+ return __real_fopen(ptr + TETHERING_TEST_FILE_PATH_LEN, mode);
+}
+
+FILE *__wrap_fopen64(const char *pathname, const char *mode)
+{
+ if (!tethering_mock_file_result)
+ return NULL;
+
+ return __wrap_fopen(pathname, mode);
+}
+
+int __wrap_rename(const char *old, const char *new)
+{
+ if (!tethering_mock_file_result)
+ return -1;
+
+ char *p_old = strstr(old, TETHERING_TEST_FILE_PATH);
+ char *p_new = strstr(new, TETHERING_TEST_FILE_PATH);
+
+ if (!p_old || !p_new)
+ return __real_rename(old, new);
+
+ return __real_rename(p_old + TETHERING_TEST_FILE_PATH_LEN,
+ p_new + TETHERING_TEST_FILE_PATH_LEN);
+}
--- /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 tethering_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 "tethering_gdbus.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+typedef struct {
+ GAsyncReadyCallback callback;
+ gpointer user_data;
+} gdbus_async_callback_info_s;
+
+typedef struct {
+ GDBusSignalCallback callback;
+ gpointer user_data;
+} gdbus_signal_callback_info_s;
+
+static const char *gdbus_signal_list[TETHERING_MOCK_GDBUS_SIGNAL_MAX] = {
+ [TETHERING_MOCK_GDBUS_SIGNAL_ON] = "soft_ap_on",
+ [TETHERING_MOCK_GDBUS_SIGNAL_OFF] = "soft_ap_off",
+ [TETHERING_MOCK_GDBUS_SIGNAL_LOW_BATTERY_MODE] = "low_batt_mode",
+ [TETHERING_MOCK_GDBUS_SIGNAL_FLIGHT_MODE] = "flight_mode",
+ [TETHERING_MOCK_GDBUS_SIGNAL_SECURITY_TYPE_CHANGED] = "security_type_changed",
+ [TETHERING_MOCK_GDBUS_SIGNAL_SSID_VISIBILITY_CHANGED] = "ssid_visibility_changed",
+ [TETHERING_MOCK_GDBUS_SIGNAL_PASSPHRASE_CHANGED] = "passphrase_changed",
+ [TETHERING_MOCK_GDBUS_SIGNAL_DHCP_STATUS] = "dhcp_status",
+};
+
+static gdbus_async_callback_info_s gdbus_async_callback = {NULL, NULL};
+static gdbus_signal_callback_info_s gdbus_signal_callbacks[TETHERING_MOCK_GDBUS_SIGNAL_MAX] = {
+ {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},
+ {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL} };
+
+static bool tethering_mock_gdbus_result;
+
+void tethering_mock_set_gdbus_result(bool value)
+{
+ tethering_mock_gdbus_result = value;
+}
+
+void tethering_mock_invoke_gdbus_async_callback(void)
+{
+ if (!gdbus_async_callback.callback)
+ return;
+
+ gdbus_async_callback.callback(NULL, NULL, gdbus_async_callback.user_data);
+ gdbus_async_callback.callback = NULL;
+ gdbus_async_callback.user_data = NULL;
+}
+
+void tethering_mock_emit_gdbus_signal(int signo)
+{
+ if (signo < TETHERING_MOCK_GDBUS_SIGNAL_ON || signo >= TETHERING_MOCK_GDBUS_SIGNAL_MAX)
+ return;
+
+ if (!gdbus_signal_callbacks[signo].callback)
+ return;
+
+ GVariant *params = NULL;
+
+ switch (signo) {
+ case TETHERING_MOCK_GDBUS_SIGNAL_ON:
+ break;
+ case TETHERING_MOCK_GDBUS_SIGNAL_OFF:
+ params = g_variant_new("(s)", "There is no connection for a while");
+ break;
+ case TETHERING_MOCK_GDBUS_SIGNAL_LOW_BATTERY_MODE:
+ case TETHERING_MOCK_GDBUS_SIGNAL_FLIGHT_MODE:
+ break;
+ case TETHERING_MOCK_GDBUS_SIGNAL_SECURITY_TYPE_CHANGED:
+ case TETHERING_MOCK_GDBUS_SIGNAL_SSID_VISIBILITY_CHANGED:
+ params = g_variant_new("(i)", 1);
+ break;
+ case TETHERING_MOCK_GDBUS_SIGNAL_PASSPHRASE_CHANGED:
+ break;
+ case TETHERING_MOCK_GDBUS_SIGNAL_DHCP_STATUS:
+ params = g_variant_new("(ssssu)", "DhcpConnected",
+ "192.168.43.24", "ab:cd:ef:ab:cd:ef",
+ "client", 1592460260);
+ break;
+ default:
+ break;
+ }
+
+ gdbus_signal_callbacks[signo].callback(NULL, NULL,
+ NULL, NULL, gdbus_signal_list[signo],
+ params, gdbus_signal_callbacks[signo].user_data);
+}
+
+GCancellable *__wrap_g_cancellable_new(void)
+{
+ return (GCancellable *)g_object_new(G_TYPE_CANCELLABLE, NULL);
+}
+
+GDBusConnection *__wrap_g_bus_get_sync(GBusType bus_type, GCancellable *cancellable, GError **error)
+{
+ return (GDBusConnection *)g_object_new(G_TYPE_DBUS_CONNECTION, NULL);
+}
+
+GDBusProxy *__wrap_g_dbus_proxy_new_sync(GDBusConnection *connection,
+ GDBusProxyFlags flags,
+ GDBusInterfaceInfo *info,
+ const gchar *name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ GCancellable *cancellable,
+ GError **error)
+{
+ return (GDBusProxy *)g_object_new(G_TYPE_DBUS_PROXY, NULL);
+}
+
+guint __wrap_g_dbus_connection_signal_subscribe(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *interface_name,
+ const gchar *member,
+ const gchar *object_path,
+ const gchar *arg0,
+ GDBusSignalFlags flags,
+ GDBusSignalCallback callback,
+ gpointer user_data,
+ GDestroyNotify user_data_free_func)
+{
+ for (int i = 1; i < TETHERING_MOCK_GDBUS_SIGNAL_MAX; i++) {
+ if (strcmp(gdbus_signal_list[i], member) == 0) {
+ gdbus_signal_callbacks[i].callback = callback;
+ gdbus_signal_callbacks[i].user_data = user_data;
+ return i;
+ }
+ }
+ return 0;
+}
+
+void __wrap_g_dbus_connection_signal_unsubscribe(GDBusConnection *connection,
+ guint subscription_id)
+{
+ if (subscription_id >= TETHERING_MOCK_GDBUS_SIGNAL_ON
+ && subscription_id < TETHERING_MOCK_GDBUS_SIGNAL_MAX) {
+ gdbus_signal_callbacks[subscription_id].callback = NULL;
+ gdbus_signal_callbacks[subscription_id].user_data = NULL;
+ }
+
+ return;
+}
+
+typedef struct {
+ int type;
+ const char *ip;
+ const char *mac;
+ const char *hostname;
+ int time;
+} clients_info_s;
+
+#define DUMMY_CLIENTS_NUM 4
+clients_info_s dummy_clients[DUMMY_CLIENTS_NUM + 1] = {
+ {0, "192.168.43.10", "aa:bb:cc:aa:bb:cc", "client1", 1592379558}, // wifi
+ {1, "192.168.129.15", "bb:cc:aa:bb:cc:aa", "client2", 1592379626}, // usb
+ {2, "192.168.130.21", "cc:aa:bb:cc:aa:bb", "client3", 1592379687}, // bluetooth
+ {3, "192.168.43.57", "ab:cd:ef:ab:cd:ef", "client4", 1592379714}, // p2p
+ {0, NULL, NULL, NULL, 0}
+};
+
+static GVariant *_get_connected_clients_info(void)
+{
+ GVariant *params = NULL;
+ GVariantBuilder *inner_builder;
+ GVariantBuilder *outer_builder;
+
+ outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a(a{sv})"));
+
+ for (int i = 0; i < DUMMY_CLIENTS_NUM; i++) {
+ inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(inner_builder, "{sv}", "Type",
+ g_variant_new_int32(dummy_clients[i].type));
+ g_variant_builder_add(inner_builder, "{sv}", "IP",
+ g_variant_new_string(dummy_clients[i].ip));
+ g_variant_builder_add(inner_builder, "{sv}", "MAC",
+ g_variant_new_string(dummy_clients[i].mac));
+ g_variant_builder_add(inner_builder, "{sv}", "Name",
+ g_variant_new_string(dummy_clients[i].hostname));
+ g_variant_builder_add(inner_builder, "{sv}", "Time",
+ g_variant_new_int32(dummy_clients[i].time));
+
+ g_variant_builder_add(outer_builder, "(@a{sv})", g_variant_builder_end(inner_builder));
+ g_variant_builder_unref(inner_builder);
+ }
+
+ params = g_variant_new("(@a(a{sv}))", g_variant_builder_end(outer_builder));
+ g_variant_builder_unref(outer_builder);
+
+ return params;
+}
+
+GVariant *__wrap_g_dbus_proxy_call_sync(GDBusProxy *proxy,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GVariant *params = NULL;
+
+ if (!tethering_mock_gdbus_result) {
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "dbus error");
+ return NULL;
+ }
+
+ if (strcmp(method_name, "get_wifi_tethering_passphrase") == 0)
+ params = g_variant_new("(siu)", "P@s$w0rd!", 9, 0);
+ else if (strcmp(method_name, "get_station_info") == 0)
+ params = _get_connected_clients_info();
+ else
+ params = g_variant_new("(u)", 0);
+
+ return params;
+}
+
+void __wrap_g_dbus_proxy_call(GDBusProxy *proxy,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ gdbus_async_callback.callback = callback;
+ gdbus_async_callback.user_data = user_data;
+}
+
+GVariant *__wrap_g_dbus_proxy_call_finish(GDBusProxy *proxy,
+ GAsyncResult *res, GError **error)
+{
+ return g_variant_new("(u)", 0);
+}
+
+void __wrap_g_dbus_proxy_set_default_timeout(GDBusProxy *proxy, gint timeout_msec)
+{
+ return;
+}
+
+gboolean __wrap_g_dbus_connection_emit_signal(GDBusConnection *connection,
+ const gchar *destination_bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ GError **error)
+{
+ return TRUE;
+}
--- /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>
+
+enum {
+ TETHERING_MOCK_GDBUS_SIGNAL_ON = 1,
+ TETHERING_MOCK_GDBUS_SIGNAL_OFF,
+ TETHERING_MOCK_GDBUS_SIGNAL_LOW_BATTERY_MODE,
+ TETHERING_MOCK_GDBUS_SIGNAL_FLIGHT_MODE,
+ TETHERING_MOCK_GDBUS_SIGNAL_SECURITY_TYPE_CHANGED,
+ TETHERING_MOCK_GDBUS_SIGNAL_SSID_VISIBILITY_CHANGED,
+ TETHERING_MOCK_GDBUS_SIGNAL_PASSPHRASE_CHANGED,
+ TETHERING_MOCK_GDBUS_SIGNAL_DHCP_STATUS,
+ TETHERING_MOCK_GDBUS_SIGNAL_MAX
+};
+
+void tethering_mock_set_gdbus_result(bool value);
+void tethering_mock_invoke_gdbus_async_callback(void);
+void tethering_mock_emit_gdbus_signal(int signo);
--- /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 <arpa/inet.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#define TETHERING_TEST_IP_ADDRESS 0xC0A82B01 /* 192.168.43.1 */
+
+static void _set_mac_address(void *arg)
+{
+ struct ifreq *ifr = (struct ifreq *) arg;
+
+ for (int i = 0; i < 6; i++)
+ ifr->ifr_hwaddr.sa_data[i] = 0x00;
+}
+
+static void _set_ip_address(void *arg)
+{
+ struct ifreq *ifr = (struct ifreq *) arg;
+ struct sockaddr_in addr;
+
+ memset(&addr, 0, sizeof(struct sockaddr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0;
+ addr.sin_addr.s_addr = htonl(TETHERING_TEST_IP_ADDRESS);
+
+ memcpy(&ifr->ifr_addr, &addr, sizeof(struct sockaddr));
+}
+
+int __wrap_ioctl(int fd, unsigned long int request, ...)
+{
+ void *arg;
+ va_list vl;
+
+ va_start(vl, request);
+ arg = va_arg(vl, void *);
+
+ switch (request) {
+ case SIOCGIFHWADDR:
+ _set_mac_address(arg);
+ break;
+ case SIOCGIFADDR:
+ _set_ip_address(arg);
+ break;
+ default:
+ return 1;
+ }
+
+ va_end(vl);
+
+ 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.
+ */
+
+#include "tethering_memory.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+static bool tethering_mock_memory_result;
+
+extern void *__real_malloc(size_t size);
+extern void *__real_calloc(size_t nmemb, size_t size);
+
+void tethering_mock_set_memory_result(bool result)
+{
+ tethering_mock_memory_result = result;
+}
+
+void *__wrap_malloc(size_t size)
+{
+ if (tethering_mock_memory_result)
+ return __real_malloc(size);
+
+ return NULL;
+}
+
+void *__wrap_calloc(size_t nmemb, size_t size)
+{
+ if (tethering_mock_memory_result)
+ return __real_calloc(nmemb, size);
+
+ return NULL;
+}
--- /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 tethering_mock_set_memory_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 "tethering_system_info.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <system_info.h>
+
+static bool tethering_mock_sysinfo_result;
+
+void tethering_mock_set_sysinfo_result(bool value)
+{
+ tethering_mock_sysinfo_result = value;
+}
+
+int __wrap_system_info_get_platform_bool(const char *key, bool *value)
+{
+ *value = tethering_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 tethering_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 "tethering_vconf.h"
+
+#include <vconf.h>
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+static bool tethering_mock_vconf_result;
+
+typedef struct {
+ bool usb;
+ bool wifi;
+ bool bluetooth;
+ bool p2p;
+} tethering_mock_enabled_state_s;
+
+static tethering_mock_enabled_state_s tethering_mock_enabled_state;
+
+extern int __real_vconf_get_int(const char *in_key, int *intval);
+
+void tethering_mock_set_vconf_result(bool result)
+{
+ tethering_mock_vconf_result = result;
+}
+
+void tethering_mock_set_enabled_state(bool usb, bool wifi, bool bluetooth, bool p2p)
+{
+ tethering_mock_enabled_state.usb = usb;
+ tethering_mock_enabled_state.wifi = wifi;
+ tethering_mock_enabled_state.bluetooth = bluetooth;
+ tethering_mock_enabled_state.p2p = p2p;
+}
+
+int __wrap_vconf_get_int(const char *in_key, int *intval)
+{
+ if (!tethering_mock_vconf_result)
+ return -1;
+
+ if (strncmp(in_key, VCONFKEY_MOBILE_HOTSPOT_MODE,
+ strlen(VCONFKEY_MOBILE_HOTSPOT_MODE)) == 0) {
+ *intval |= tethering_mock_enabled_state.usb ? VCONFKEY_MOBILE_HOTSPOT_MODE_USB : 0;
+ *intval |= tethering_mock_enabled_state.wifi ? VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI : 0;
+ *intval |= tethering_mock_enabled_state.bluetooth ? VCONFKEY_MOBILE_HOTSPOT_MODE_BT : 0;
+ *intval |= tethering_mock_enabled_state.p2p ? VCONFKEY_MOBILE_HOTSPOT_MODE_P2P : 0;
+ } else {
+ *intval = 0;
+ }
+
+ return 0;
+}
+
+int __wrap_vconf_set_int(const char *key, int intval)
+{
+ if (!tethering_mock_vconf_result)
+ return -1;
+
+ return 0;
+}
+
+char *__wrap_vconf_get_str(const char *key)
+{
+ if (!tethering_mock_vconf_result)
+ return NULL;
+
+ return strdup("vconf result string");
+}
--- /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 tethering_mock_set_vconf_result(bool result);
+void tethering_mock_set_enabled_state(bool usb, bool wifi, bool bluetooth, bool p2p);
--- /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 "tethering.h"
+
+extern "C" {
+#include "mocks/tethering_dummy_client.h"
+#include "mocks/tethering_memory.h"
+#include "mocks/tethering_system_info.h"
+#include "mocks/tethering_vconf.h"
+}
+
+class TetheringClientTest: public ::testing::Test {
+ protected:
+ tethering_client_h client;
+
+ void SetUp() override
+ {
+ tethering_mock_set_memory_result(true);
+ tethering_mock_set_sysinfo_result(true);
+ tethering_mock_set_vconf_result(true);
+ tethering_mock_create_dummy_client(&client);
+ }
+
+ void TearDown() override
+ {
+ tethering_mock_set_vconf_result(false);
+ tethering_mock_set_sysinfo_result(false);
+ tethering_mock_set_memory_result(true);
+ tethering_mock_destroy_dummy_client(client);
+ }
+};
+
+TEST_F(TetheringClientTest, CloneN)
+{
+ tethering_client_h clone = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_clone(NULL, client));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_clone(&clone, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_clone(NULL, NULL));
+
+ tethering_mock_set_memory_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OUT_OF_MEMORY, tethering_client_clone(&clone, client));
+}
+
+TEST_F(TetheringClientTest, CloneP)
+{
+ tethering_client_h clone = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_clone(&clone, client));
+
+ tethering_client_destroy(clone);
+}
+
+TEST_F(TetheringClientTest, DestroyN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_destroy(NULL));
+}
+
+TEST_F(TetheringClientTest, DestroyP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_destroy(client));
+ client = NULL;
+}
+
+TEST_F(TetheringClientTest, GetTetheringTypeN)
+{
+ tethering_type_e type;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_tethering_type(NULL, &type));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_tethering_type(client, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_tethering_type(NULL, NULL));
+}
+
+TEST_F(TetheringClientTest, GetTetheringTypeP)
+{
+ tethering_type_e type;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_get_tethering_type(client, &type));
+}
+
+TEST_F(TetheringClientTest, GetNameN)
+{
+ char *name = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_name(NULL, &name));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_name(client, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_name(NULL, NULL));
+}
+
+TEST_F(TetheringClientTest, GetNameP)
+{
+ char *name = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_get_name(client, &name));
+
+ free(name);
+}
+
+TEST_F(TetheringClientTest, GetIpAddressN)
+{
+ char *ip_address = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_client_get_ip_address(NULL, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_client_get_ip_address(client, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_client_get_ip_address(NULL, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+}
+
+TEST_F(TetheringClientTest, GetIpAddressP)
+{
+ char *ip_address = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_client_get_ip_address(client, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address));
+
+ free(ip_address);
+}
+
+TEST_F(TetheringClientTest, GetMacAddressN)
+{
+ char *mac_address = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_mac_address(NULL, &mac_address));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_mac_address(client, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_mac_address(NULL, NULL));
+}
+
+TEST_F(TetheringClientTest, GetMacAddressP)
+{
+ char *mac_address = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_get_mac_address(client, &mac_address));
+
+ free(mac_address);
+}
+
+TEST_F(TetheringClientTest, GetTimeN)
+{
+ time_t timestamp;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_time(NULL, ×tamp));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_time(client, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_client_get_time(NULL, NULL));
+}
+
+TEST_F(TetheringClientTest, GetTimeP)
+{
+ time_t timestamp;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_client_get_time(client, ×tamp));
+}
--- /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 "tethering.h"
+
+extern "C" {
+#include "mocks/tethering_file.h"
+#include "mocks/tethering_gdbus.h"
+#include "mocks/tethering_memory.h"
+#include "mocks/tethering_system_info.h"
+#include "mocks/tethering_vconf.h"
+}
+
+class TetheringTest: public ::testing::Test {
+ protected:
+ tethering_h handle;
+
+ void SetUp() override
+ {
+ tethering_mock_set_gdbus_result(true);
+ tethering_mock_set_memory_result(true);
+ tethering_mock_set_sysinfo_result(true);
+ tethering_mock_set_vconf_result(true);
+ tethering_mock_set_file_result(true);
+ tethering_create(&handle);
+ tethering_mock_set_enabled_state(true, true, true, true);
+ }
+
+ void TearDown() override
+ {
+ tethering_mock_set_enabled_state(false, false, false, false);
+ tethering_destroy(handle);
+ tethering_mock_set_file_result(true);
+ tethering_mock_set_vconf_result(false);
+ tethering_mock_set_sysinfo_result(false);
+ tethering_mock_set_memory_result(true);
+ tethering_mock_set_gdbus_result(false);
+ }
+};
+
+bool ConnectedClientsCallbackP(tethering_client_h client, void *data)
+{
+ return true;
+}
+
+bool ConnectedClientsCallbackN(tethering_client_h client, void *data)
+{
+ return false;
+}
+
+TEST_F(TetheringTest, CreateHandleN)
+{
+ tethering_h test_handle = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_create(NULL));
+
+ tethering_mock_set_memory_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OUT_OF_MEMORY, tethering_create(&test_handle));
+}
+
+TEST_F(TetheringTest, CreateHandleP)
+{
+ tethering_h test_handle = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_create(&test_handle));
+
+ tethering_destroy(test_handle);
+}
+
+TEST_F(TetheringTest, DestroyHandleN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_destroy(NULL));
+}
+
+TEST_F(TetheringTest, DestroyHandleP)
+{
+ tethering_h test_handle = NULL;
+
+ tethering_create(&test_handle);
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_destroy(test_handle));
+}
+
+TEST_F(TetheringTest, IsEnabledN)
+{
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_ALL));
+
+ tethering_mock_set_vconf_result(false);
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_USB));
+}
+
+TEST_F(TetheringTest, IsEnabledP)
+{
+ tethering_mock_set_enabled_state(true, true, true, true);
+ EXPECT_EQ(true, tethering_is_enabled(handle, TETHERING_TYPE_USB));
+ EXPECT_EQ(true, tethering_is_enabled(handle, TETHERING_TYPE_WIFI));
+ EXPECT_EQ(true, tethering_is_enabled(handle, TETHERING_TYPE_BT));
+ EXPECT_EQ(true, tethering_is_enabled(handle, TETHERING_TYPE_P2P));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_USB));
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_WIFI));
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_BT));
+ EXPECT_EQ(false, tethering_is_enabled(handle, TETHERING_TYPE_P2P));
+}
+
+TEST_F(TetheringTest, GetMacAddressN)
+{
+ char *mac = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_mac_address(NULL, TETHERING_TYPE_USB, &mac));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_mac_address(handle, TETHERING_TYPE_USB, NULL));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_mac_address(handle, TETHERING_TYPE_USB, &mac));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_mac_address(handle, TETHERING_TYPE_WIFI, &mac));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_mac_address(handle, TETHERING_TYPE_BT, &mac));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_mac_address(handle, TETHERING_TYPE_P2P, &mac));
+}
+
+TEST_F(TetheringTest, GetMacAddressP)
+{
+ char *mac = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_mac_address(handle, TETHERING_TYPE_USB, &mac));
+ free(mac);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_mac_address(handle, TETHERING_TYPE_WIFI, &mac));
+ free(mac);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_mac_address(handle, TETHERING_TYPE_BT, &mac));
+ free(mac);
+}
+
+TEST_F(TetheringTest, GetNetworkInterfaceNameN)
+{
+ char *interface_name = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_network_interface_name(NULL, TETHERING_TYPE_USB, &interface_name));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_USB, NULL));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_USB, &interface_name));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_WIFI, &interface_name));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_BT, &interface_name));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_P2P, &interface_name));
+}
+
+TEST_F(TetheringTest, GetNetworkInterfaceNameP)
+{
+ char *interface_name = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_USB, &interface_name));
+ free(interface_name);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_WIFI, &interface_name));
+ free(interface_name);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_network_interface_name(handle, TETHERING_TYPE_BT, &interface_name));
+ free(interface_name);
+}
+
+TEST_F(TetheringTest, GetIpAddressN)
+{
+ char *ip = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_ip_address(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_ip_address(handle,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_ip_address(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_ip_address(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_ip_address(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_ip_address(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_ip_address(handle, TETHERING_TYPE_P2P,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+}
+
+TEST_F(TetheringTest, GetIpAddressP)
+{
+ char *ip = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_ip_address(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ free(ip);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_ip_address(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ free(ip);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_ip_address(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &ip));
+ free(ip);
+}
+
+TEST_F(TetheringTest, GetGatewayAddressN)
+{
+ char *gateway = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_gateway_address(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_gateway_address(handle,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_gateway_address(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_P2P,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+}
+
+TEST_F(TetheringTest, GetGatewayAddressP)
+{
+ char *gateway = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ free(gateway);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ free(gateway);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_gateway_address(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &gateway));
+ free(gateway);
+}
+
+TEST_F(TetheringTest, GetSubnetMaskN)
+{
+ char *subnetmask = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_subnet_mask(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_subnet_mask(handle,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_get_subnet_mask(NULL,
+ TETHERING_TYPE_USB, TETHERING_ADDRESS_FAMILY_IPV4, NULL));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_P2P,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+}
+
+TEST_F(TetheringTest, GetSubnetMaskP)
+{
+ char *subnetmask = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_USB,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ free(subnetmask);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_WIFI,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ free(subnetmask);
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_get_subnet_mask(handle, TETHERING_TYPE_BT,
+ TETHERING_ADDRESS_FAMILY_IPV4, &subnetmask));
+ free(subnetmask);
+}
+
+TEST_F(TetheringTest, ForeachConnectedClientsN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_foreach_connected_clients(NULL, TETHERING_TYPE_USB,
+ ConnectedClientsCallbackN, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_USB, NULL, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_foreach_connected_clients(NULL, TETHERING_TYPE_USB, NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_USB,
+ ConnectedClientsCallbackN, NULL));
+
+ tethering_mock_set_gdbus_result(true);
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_USB,
+ ConnectedClientsCallbackN, NULL));
+}
+
+TEST_F(TetheringTest, ForeachConnectedClientsP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_USB,
+ ConnectedClientsCallbackP, NULL));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_WIFI,
+ ConnectedClientsCallbackP, NULL));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_BT,
+ ConnectedClientsCallbackP, NULL));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_foreach_connected_clients(handle, TETHERING_TYPE_P2P,
+ ConnectedClientsCallbackP, NULL));
+}
--- /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();
+}
--- /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 "tethering.h"
+
+extern "C" {
+#include "mocks/tethering_file.h"
+#include "mocks/tethering_gdbus.h"
+#include "mocks/tethering_memory.h"
+#include "mocks/tethering_system_info.h"
+#include "mocks/tethering_vconf.h"
+}
+
+class WiFiTetheringTest: public ::testing::Test {
+ protected:
+ tethering_h handle;
+
+ void SetUp() override
+ {
+ tethering_mock_set_gdbus_result(true);
+ tethering_mock_set_memory_result(true);
+ tethering_mock_set_sysinfo_result(true);
+ tethering_mock_set_vconf_result(true);
+ tethering_mock_set_file_result(true);
+
+ tethering_create(&handle);
+ tethering_mock_set_enabled_state(true, true, true, true);
+ }
+
+ void TearDown() override
+ {
+ tethering_mock_set_enabled_state(false, false, false, false);
+ tethering_destroy(handle);
+
+ tethering_mock_set_file_result(true);
+ tethering_mock_set_vconf_result(false);
+ tethering_mock_set_sysinfo_result(false);
+ tethering_mock_set_memory_result(true);
+ tethering_mock_set_gdbus_result(false);
+ }
+};
+
+TEST_F(WiFiTetheringTest, SetSecurityTypeN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_security_type(NULL, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_security_type(handle, (tethering_wifi_security_type_e)-1));
+}
+
+TEST_F(WiFiTetheringTest, SetSecurityTypeP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_NONE));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPS));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_SAE));
+}
+
+TEST_F(WiFiTetheringTest, GetSecurityTypeN)
+{
+ tethering_wifi_security_type_e type;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_security_type(NULL, &type));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_security_type(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_security_type(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetSecurityTypeP)
+{
+ tethering_wifi_security_type_e type;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_security_type(handle, &type));
+}
+
+TEST_F(WiFiTetheringTest, SetSsidN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_ssid(NULL, "tethering-gtest"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_ssid(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_ssid(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, SetSsidP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_ssid(handle, "tethering-gtest"));
+}
+
+TEST_F(WiFiTetheringTest, GetSsidN)
+{
+ char *ssid = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid(NULL, &ssid));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetSsidP)
+{
+ char *ssid = NULL;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_ssid(handle, &ssid));
+
+ free(ssid);
+}
+
+TEST_F(WiFiTetheringTest, SetSsidVisibilityN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_ssid_visibility(NULL, true));
+}
+
+TEST_F(WiFiTetheringTest, SetSsidVisibilityP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_ssid_visibility(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, GetSsidVisibilityN)
+{
+ bool visible;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid_visibility(NULL, &visible));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid_visibility(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_ssid_visibility(NULL, NULL));
+
+ tethering_mock_set_vconf_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_get_ssid_visibility(handle, &visible));
+}
+
+TEST_F(WiFiTetheringTest, GetSsidVisibilityP)
+{
+ bool visible;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_ssid_visibility(handle, &visible));
+}
+
+TEST_F(WiFiTetheringTest, SetPassphraseN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_passphrase(NULL, "P@s$w0rd!"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_passphrase(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_passphrase(NULL, NULL));
+
+ // Too short passphrase
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_passphrase(handle, "123"));
+
+ // Too long passphrase
+ char passphrase[70] = {0, };
+ for (int i = 0; i < 69; i++)
+ passphrase[i] = 'a';
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_passphrase(handle, passphrase));
+}
+
+TEST_F(WiFiTetheringTest, SetPassphraseP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_passphrase(handle, "P@s$w0rd!"));
+}
+
+TEST_F(WiFiTetheringTest, GetPassphraseN)
+{
+ char *passphrase;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_passphrase(NULL, &passphrase));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_passphrase(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_passphrase(NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_get_passphrase(handle, &passphrase));
+}
+
+TEST_F(WiFiTetheringTest, GetPassphraseP)
+{
+ char *passphrase;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_passphrase(handle, &passphrase));
+
+ free(passphrase);
+}
+
+TEST_F(WiFiTetheringTest, SetMacFilterN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_mac_filter(NULL, true));
+}
+
+TEST_F(WiFiTetheringTest, SetMacFilterP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_mac_filter(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, GetMacFilterN)
+{
+ bool mac_filter;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mac_filter(NULL, &mac_filter));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mac_filter(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mac_filter(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetMacFilterP)
+{
+ bool mac_filter;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_mac_filter(handle, &mac_filter));
+}
+
+TEST_F(WiFiTetheringTest, AddAllowedMacListN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_allowed_mac_list(NULL, "aa:bb:cc:aa:bb:cc"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_add_allowed_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_add_allowed_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, AddAllowedMacListP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_allowed_mac_list(handle, "aa:bb:cc:aa:bb:cc"));
+}
+
+TEST_F(WiFiTetheringTest, RemoveAllowedMacListN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_allowed_mac_list(NULL, "aa:bb:cc:aa:bb:cc"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_allowed_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_allowed_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, RemoveAllowedMacListP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_remove_allowed_mac_list(handle, "aa:bb:cc:aa:bb:cc"));
+}
+
+TEST_F(WiFiTetheringTest, GetAllowedMacListN)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_allowed_mac_list(NULL, &list));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_allowed_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_allowed_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetAllowedMacListP)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_allowed_mac_list(handle, &list));
+}
+
+TEST_F(WiFiTetheringTest, AddBlockedMacListN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_blocked_mac_list(NULL, "aa:bb:cc:aa:bb:cc"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_add_blocked_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_add_blocked_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, AddBlockedMacListP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_blocked_mac_list(handle, "aa:bb:cc:aa:bb:cc"));
+}
+
+TEST_F(WiFiTetheringTest, RemoveBlockedMacListN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_blocked_mac_list(NULL, "aa:bb:cc:aa:bb:cc"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_blocked_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_remove_blocked_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, RemoveBlockedMacListP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_remove_blocked_mac_list(handle, "aa:bb:cc:aa:bb:cc"));
+}
+
+TEST_F(WiFiTetheringTest, GetBlockedMacListN)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_blocked_mac_list(NULL, &list));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_blocked_mac_list(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_blocked_mac_list(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetBlockedMacListP)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_blocked_mac_list(handle, &list));
+}
+
+TEST_F(WiFiTetheringTest, EnableDhcpN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_enable_dhcp(NULL, true));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_enable_dhcp(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, EnableDhcpP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_enable_dhcp(handle, true));
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_enable_dhcp(handle, false));
+}
+
+
+TEST_F(WiFiTetheringTest, SetDhcpRangeN)
+{
+ char start_ip[16] = "192.168.43.2";
+ char end_ip[16] = "192.168.43.100";
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_dhcp_range(NULL, start_ip, end_ip));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_dhcp_range(handle, NULL, end_ip));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_dhcp_range(handle, start_ip, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_dhcp_range(NULL, NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_set_dhcp_range(handle, start_ip, end_ip));
+}
+
+TEST_F(WiFiTetheringTest, EnableDhcpWithRangeP)
+{
+ char start_ip[16] = "192.168.43.2";
+ char end_ip[16] = "192.168.43.100";
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_dhcp_range(handle, start_ip, end_ip));
+}
+
+TEST_F(WiFiTetheringTest, IsDhcpEnabledN)
+{
+ bool dhcp_enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_is_dhcp_enabled(NULL, &dhcp_enabled));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_is_dhcp_enabled(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_is_dhcp_enabled(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, IsDhcpEnabledP)
+{
+ bool dhcp_enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_is_dhcp_enabled(handle, &dhcp_enabled));
+}
+
+TEST_F(WiFiTetheringTest, SetChannelN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_channel(NULL, 6));
+}
+
+TEST_F(WiFiTetheringTest, SetChannelP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_channel(handle, 6));
+}
+
+TEST_F(WiFiTetheringTest, GetChannelN)
+{
+ int channel;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_channel(NULL, &channel));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_channel(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_channel(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetChannelP)
+{
+ int channel;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_channel(handle, &channel));
+}
+
+TEST_F(WiFiTetheringTest, SetModeN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_mode(NULL, TETHERING_WIFI_MODE_TYPE_B));
+}
+
+TEST_F(WiFiTetheringTest, SetModeP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_mode(handle, TETHERING_WIFI_MODE_TYPE_B));
+}
+
+TEST_F(WiFiTetheringTest, GetModeN)
+{
+ tethering_wifi_mode_type_e mode;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mode(NULL, &mode));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mode(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_mode(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetModeP)
+{
+ tethering_wifi_mode_type_e mode;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_mode(handle, &mode));
+}
+
+TEST_F(WiFiTetheringTest, SetTxPowerN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_txpower(NULL, 100));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_set_txpower(handle, 100));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED, tethering_wifi_set_txpower(handle, 100));
+}
+
+TEST_F(WiFiTetheringTest, SetTxPowerP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_txpower(handle, 100));
+}
+
+TEST_F(WiFiTetheringTest, GetTxPowerN)
+{
+ unsigned int txpower = 0;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_txpower(NULL, &txpower));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_txpower(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_get_txpower(NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_get_txpower(handle, &txpower));
+
+ tethering_mock_set_enabled_state(false, false, false, false);
+ EXPECT_EQ(TETHERING_ERROR_NOT_ENABLED, tethering_wifi_get_txpower(handle, &txpower));
+}
+
+TEST_F(WiFiTetheringTest, GetTxPowerP)
+{
+ unsigned int txpower = 0;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_txpower(handle, &txpower));
+}
+
+TEST_F(WiFiTetheringTest, SetMtuN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_mtu(NULL, 100));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_set_mtu(handle, 100));
+}
+
+TEST_F(WiFiTetheringTest, SetMtuP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_mtu(handle, 100));
+}
+
+TEST_F(WiFiTetheringTest, ChangeMacN)
+{
+ char mac[18] = "aa:bb:cc:aa:bb:cc";
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_change_mac(NULL, mac));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_change_mac(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_change_mac(NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_change_mac(handle, mac));
+}
+
+TEST_F(WiFiTetheringTest, ChangeMacP)
+{
+ char mac[18] = "aa:bb:cc:aa:bb:cc";
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_change_mac(handle, mac));
+}
+
+TEST_F(WiFiTetheringTest, SetMaxConnectedDeviceN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_max_connected_device(NULL, 10));
+}
+
+TEST_F(WiFiTetheringTest, SetMaxConnectedDeviceP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_max_connected_device(handle, 10));
+}
+
+TEST_F(WiFiTetheringTest, GetMaxConnectedDeviceN)
+{
+ int num;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_max_connected_device(NULL, &num));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_max_connected_device(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_max_connected_device(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetMaxConnectedDeviceP)
+{
+ int num;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_get_max_connected_device(handle, &num));
+}
+
+TEST_F(WiFiTetheringTest, EnablePortForwardingN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_enable_port_forwarding(NULL, true));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_enable_port_forwarding(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, EnablePortForwardingP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_enable_port_forwarding(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, AddPortForwardingRuleN)
+{
+ char ifname[6] = "wlan0";
+ char protocol[16] = "tcp";
+ char org_ip[18] = "192.168.43.2";
+ char final_ip[18] = "192.168.43.123";
+ int org_port = 1234;
+ int final_port = 2341;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_forwarding_rule(NULL,
+ ifname, protocol, org_ip, org_port, final_ip, final_port));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ NULL, protocol, org_ip, org_port, final_ip, final_port));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ ifname, NULL, org_ip, org_port, final_ip, final_port));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ ifname, protocol, NULL, org_port, final_ip, final_port));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ ifname, protocol, org_ip, org_port, NULL, final_port));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ ifname, protocol, org_ip, org_port, final_ip, final_port));
+}
+
+TEST_F(WiFiTetheringTest, AddPortForwardingRuleP)
+{
+ char ifname[6] = "wlan0";
+ char protocol[16] = "tcp";
+ char org_ip[18] = "192.168.43.2";
+ char final_ip[18] = "192.168.43.123";
+ int org_port = 1234;
+ int final_port = 2341;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_port_forwarding_rule(handle,
+ ifname, protocol, org_ip, org_port, final_ip, final_port));
+}
+
+TEST_F(WiFiTetheringTest, ResetPortForwardingRuleN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_reset_port_forwarding_rule(NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_reset_port_forwarding_rule(handle));
+}
+
+TEST_F(WiFiTetheringTest, ResetPortForwardingRuleP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_reset_port_forwarding_rule(handle));
+}
+
+TEST_F(WiFiTetheringTest, IsPortForwardingEnabledN)
+{
+ bool enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_forwarding_enabled(NULL, &enabled));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_forwarding_enabled(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_forwarding_enabled(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, IsPortForwardingEnabledP)
+{
+ bool enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_is_port_forwarding_enabled(handle, &enabled));
+}
+
+TEST_F(WiFiTetheringTest, GetPortForwardingRuleN)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_forwarding_rule(NULL, &list));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_forwarding_rule(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_forwarding_rule(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetPortForwardingRuleP)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_get_port_forwarding_rule(handle, &list));
+}
+
+TEST_F(WiFiTetheringTest, EnablePortFilteringN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_enable_port_filtering(NULL, true));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_enable_port_filtering(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, EnablePortFilteringP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_enable_port_filtering(handle, true));
+}
+
+TEST_F(WiFiTetheringTest, AddPortFilteringRuleN)
+{
+ char protocol[4] = "tcp";
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_filtering_rule(NULL, 1234, protocol, true));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_port_filtering_rule(handle, 1234, NULL, true));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_add_port_filtering_rule(handle, 1234, protocol, true));
+}
+
+TEST_F(WiFiTetheringTest, AddPortFilteringRuleP)
+{
+ char protocol[4] = "tcp";
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_port_filtering_rule(handle, 1234, protocol, true));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_port_filtering_rule(handle, 1234, protocol, false));
+}
+
+TEST_F(WiFiTetheringTest, AddCustomPortFilteringRuleN)
+{
+ char protocol[4] = "tcp";
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_custom_port_filtering_rule(NULL, 1234, 2341, protocol, true));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_add_custom_port_filtering_rule(handle, 1234, 2341, NULL, true));
+
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_add_custom_port_filtering_rule(handle, 1234, 2341, protocol, true));
+}
+
+TEST_F(WiFiTetheringTest, AddCustomPortFilteringRuleP)
+{
+ char protocol[4] = "tcp";
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_custom_port_filtering_rule(handle, 1234, 2341, protocol, true));
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_add_custom_port_filtering_rule(handle, 1234, 2341, protocol, false));
+
+}
+
+TEST_F(WiFiTetheringTest, GetPortFilteringRuleN)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_filtering_rule(NULL, &list));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_filtering_rule(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_port_filtering_rule(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetPortFilteringRuleP)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_get_port_filtering_rule(handle, &list));
+}
+
+TEST_F(WiFiTetheringTest, GetCustomPortFilteringRuleN)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_custom_port_filtering_rule(NULL, &list));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_custom_port_filtering_rule(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_get_custom_port_filtering_rule(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, GetCustomPortFilteringRuleP)
+{
+ void *list;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_get_custom_port_filtering_rule(handle, &list));
+}
+
+TEST_F(WiFiTetheringTest, IsPortFilteringEnabledN)
+{
+ bool enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_filtering_enabled(NULL, &enabled));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_filtering_enabled(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_is_port_filtering_enabled(NULL, NULL));
+}
+
+TEST_F(WiFiTetheringTest, IsPortFilteringEnabledP)
+{
+ bool enabled;
+
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_is_port_filtering_enabled(handle, &enabled));
+}
+
+TEST_F(WiFiTetheringTest, SetVpnPassthroughRuleN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER,
+ tethering_wifi_set_vpn_passthrough_rule(NULL, TETHERING_TYPE_IPSEC_PASSTHROUGH, true));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED,
+ tethering_wifi_set_vpn_passthrough_rule(handle, TETHERING_TYPE_IPSEC_PASSTHROUGH, true));
+
+}
+
+TEST_F(WiFiTetheringTest, SetVpnPassthroughRuleP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE,
+ tethering_wifi_set_vpn_passthrough_rule(handle, TETHERING_TYPE_IPSEC_PASSTHROUGH, true));
+}
+
+TEST_F(WiFiTetheringTest, PushWpsButtonN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_push_wps_button(NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_push_wps_button(handle));
+}
+
+TEST_F(WiFiTetheringTest, PushWpsButtonP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_push_wps_button(handle));
+}
+
+TEST_F(WiFiTetheringTest, SetWpsPinN)
+{
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_wps_pin(NULL, "1234567"));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_wps_pin(handle, NULL));
+ EXPECT_EQ(TETHERING_ERROR_INVALID_PARAMETER, tethering_wifi_set_wps_pin(NULL, NULL));
+
+ tethering_mock_set_gdbus_result(false);
+ EXPECT_EQ(TETHERING_ERROR_OPERATION_FAILED, tethering_wifi_set_wps_pin(handle, "1234567"));
+}
+
+TEST_F(WiFiTetheringTest, SetWpsPinP)
+{
+ EXPECT_EQ(TETHERING_ERROR_NONE, tethering_wifi_set_wps_pin(handle, "1234567"));
+}