From 47b0f2399ffcd88faccbb5729ff0e14eb7609b0c Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Wed, 24 Jun 2020 15:38:32 +0900 Subject: [PATCH] Add gtest for line coverage - Add testcases for sync API - Remove LCOV macro - Fix some bugs (memory leak, ...) Change-Id: Ib57df16aa1c56e34a623fdb05e5cdb4f39c197cc --- CMakeLists.txt | 3 +- packaging/capi-network-tethering.spec | 20 +- src/tethering.c | 208 +++------ src/tethering_client.c | 5 + src/tethering_private.c | 4 - tests/CMakeLists.txt | 34 ++ tests/mocks/tethering_dummy_client.c | 58 +++ tests/mocks/tethering_dummy_client.h | 20 + tests/mocks/tethering_file.c | 70 +++ tests/mocks/tethering_file.h | 21 + tests/mocks/tethering_gdbus.c | 267 +++++++++++ tests/mocks/tethering_gdbus.h | 35 ++ tests/mocks/tethering_ioctl.c | 69 +++ tests/mocks/tethering_memory.c | 47 ++ tests/mocks/tethering_memory.h | 21 + tests/mocks/tethering_system_info.c | 35 ++ tests/mocks/tethering_system_info.h | 21 + tests/mocks/tethering_vconf.c | 82 ++++ tests/mocks/tethering_vconf.h | 22 + tests/tethering-gtest-client.cpp | 169 +++++++ tests/tethering-gtest-common.cpp | 378 ++++++++++++++++ tests/tethering-gtest-main.cpp | 23 + tests/tethering-gtest-wifi.cpp | 802 ++++++++++++++++++++++++++++++++++ {test => tools}/CMakeLists.txt | 0 {test => tools}/tethering_test.c | 0 25 files changed, 2259 insertions(+), 155 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/mocks/tethering_dummy_client.c create mode 100644 tests/mocks/tethering_dummy_client.h create mode 100644 tests/mocks/tethering_file.c create mode 100644 tests/mocks/tethering_file.h create mode 100644 tests/mocks/tethering_gdbus.c create mode 100644 tests/mocks/tethering_gdbus.h create mode 100644 tests/mocks/tethering_ioctl.c create mode 100644 tests/mocks/tethering_memory.c create mode 100644 tests/mocks/tethering_memory.h create mode 100644 tests/mocks/tethering_system_info.c create mode 100644 tests/mocks/tethering_system_info.h create mode 100644 tests/mocks/tethering_vconf.c create mode 100644 tests/mocks/tethering_vconf.h create mode 100755 tests/tethering-gtest-client.cpp create mode 100755 tests/tethering-gtest-common.cpp create mode 100755 tests/tethering-gtest-main.cpp create mode 100755 tests/tethering-gtest-wifi.cpp rename {test => tools}/CMakeLists.txt (100%) rename {test => tools}/tethering_test.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27fdf76..05ca685 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,8 @@ CONFIGURE_FILE( ) 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) diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index 9d03489..bb579ab 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -14,9 +14,11 @@ BuildRequires: pkgconfig(vconf) 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 @@ -60,17 +62,21 @@ export LDFLAGS+=" -lgcov" 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 diff --git a/src/tethering.c b/src/tethering.c index c532fa0..bf4551c 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -131,7 +131,7 @@ static int retry = 0; 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; @@ -142,8 +142,8 @@ static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, c 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); } } @@ -164,12 +164,12 @@ static tethering_error_e __set_security_type(const tethering_wifi_security_type_ 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; } @@ -179,13 +179,13 @@ static tethering_error_e __set_security_type(const tethering_wifi_security_type_ 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; } @@ -216,7 +216,7 @@ static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int siz 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; } @@ -226,14 +226,14 @@ static tethering_error_e __set_visible(const bool visible) 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; } @@ -271,11 +271,9 @@ static tethering_error_e __get_error(int agent_error) 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; @@ -285,7 +283,6 @@ static tethering_error_e __get_error(int agent_error) err = TETHERING_ERROR_INVALID_PARAMETER; break; - //LCOV_EXCL_START case MOBILE_AP_ERROR_ALREADY_ENABLED: err = TETHERING_ERROR_OPERATION_FAILED; break; @@ -317,7 +314,6 @@ static tethering_error_e __get_error(int agent_error) 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; @@ -327,7 +323,6 @@ static tethering_error_e __get_error(int agent_error) 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) @@ -421,7 +416,6 @@ static void __handle_net_closed(GDBusConnection *connection, const gchar *sender 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, @@ -477,7 +471,6 @@ static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *s 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) @@ -529,7 +522,6 @@ static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *se 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, @@ -585,7 +577,6 @@ static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sen 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) @@ -660,7 +651,6 @@ static void __handle_flight_mode(GDBusConnection *connection, const gchar *sende } 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, @@ -692,7 +682,7 @@ static void __handle_security_type_changed(GDBusConnection *connection, const gc 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; } @@ -706,7 +696,7 @@ static void __handle_ssid_visibility_changed(GDBusConnection *connection, const 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; @@ -718,7 +708,7 @@ static void __handle_ssid_visibility_changed(GDBusConnection *connection, const scb = th->ssid_visibility_changed_cb; if (scb == NULL) { - DBG("-\n"); //LCOV_EXCL_LINE + DBG("-\n"); return; } g_variant_get(parameters, "(s)", &buf); @@ -728,14 +718,14 @@ static void __handle_ssid_visibility_changed(GDBusConnection *connection, const 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; @@ -750,13 +740,13 @@ static void __handle_passphrase_changed(GDBusConnection *connection, const gchar 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; @@ -772,7 +762,6 @@ static void __wifi_enabled_cfm_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 error [%s]\n", g_error->message); if (g_error->code == G_DBUS_ERROR_NO_REPLY && ++retry < TETHERING_ERROR_RECOVERY_MAX) { @@ -784,14 +773,13 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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, @@ -799,18 +787,18 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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; @@ -826,7 +814,6 @@ static void __bt_enabled_cfm_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 error [%s]\n", g_error->message); if (g_error->code == G_DBUS_ERROR_NO_REPLY && ++retry < TETHERING_ERROR_RECOVERY_MAX) { @@ -840,7 +827,6 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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); @@ -854,7 +840,7 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL); if (!ecb) { - DBG("-\n"); //LCOV_EXCL_LINE + DBG("-\n"); return; } @@ -862,7 +848,6 @@ static void __bt_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, DBG("-\n"); } -//LCOV_EXCL_START static void __usb_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) { @@ -963,12 +948,11 @@ static void __p2p_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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; @@ -987,11 +971,9 @@ static void __disabled_cfm_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 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); @@ -1025,7 +1007,6 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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, @@ -1075,9 +1056,8 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res, 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, @@ -1097,7 +1077,6 @@ 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; @@ -1105,10 +1084,9 @@ static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res, 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) { @@ -1139,7 +1117,7 @@ static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res, 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 @@ -1206,24 +1184,18 @@ static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len) _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; } @@ -1233,23 +1205,18 @@ static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int le _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; } @@ -1257,7 +1224,7 @@ static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int le 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; } @@ -1312,7 +1279,7 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se 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; } @@ -1354,7 +1321,6 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se 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) @@ -1364,7 +1330,6 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se g_error_free(error); return ret; - //LCOV_EXCL_STOP } if (parameters != NULL) { @@ -1445,19 +1410,15 @@ API int tethering_create(tethering_h *tethering) 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) @@ -1466,14 +1427,12 @@ API int tethering_create(tethering_h *tethering) 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; @@ -1481,7 +1440,6 @@ API int tethering_create(tethering_h *tethering) 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); @@ -1489,7 +1447,6 @@ API int tethering_create(tethering_h *tethering) g_object_unref(th->client_bus); free(th); return TETHERING_ERROR_OPERATION_FAILED; - //LCOV_EXCL_STOP } __connect_signals((tethering_h)th); @@ -1575,15 +1532,12 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) 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); @@ -1593,18 +1547,15 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) 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); @@ -1627,7 +1578,6 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) break; - //LCOV_EXCL_START case TETHERING_TYPE_P2P: { _softap_settings_t p2p_set = {"", "", "", 0, false}; ret = __prepare_wifi_settings(tethering, &p2p_set); @@ -1693,7 +1643,6 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) DBG("-\n"); return TETHERING_ERROR_INVALID_PARAMETER; } - //LCOV_EXCL_STOP g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); INFO("-\n"); @@ -1719,11 +1668,9 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type) 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) { @@ -1870,7 +1817,6 @@ API int tethering_disable(tethering_h tethering, tethering_type_e 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); @@ -1881,7 +1827,6 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type) (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); break; - //LCOV_EXCL_STOP case TETHERING_TYPE_WIFI: @@ -1905,7 +1850,6 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type) (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, @@ -1942,7 +1886,6 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type) ERR("Not supported tethering type [%d]\n", type); DBG("-\n"); return TETHERING_ERROR_INVALID_PARAMETER; - //LCOV_EXCL_STOP } INFO("-\n"); return TETHERING_ERROR_NONE; @@ -2017,9 +1960,9 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) 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, @@ -2041,11 +1984,9 @@ API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, _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); @@ -2136,9 +2077,9 @@ API int tethering_get_network_interface_name(tethering_h tethering, tethering_ty 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, @@ -2357,10 +2298,14 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ 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)) { @@ -2421,7 +2366,6 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ 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; @@ -2429,9 +2373,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ 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; @@ -2904,7 +2846,6 @@ API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_s 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; @@ -2945,6 +2886,8 @@ API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_s 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"); @@ -3046,7 +2989,7 @@ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid) } if (*ssid == NULL) { - ERR("strdup is failed\n"); //LCOV_EXCL_LINE + ERR("strdup is failed\n"); return TETHERING_ERROR_OUT_OF_MEMORY; } @@ -3110,6 +3053,8 @@ API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible) 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"); @@ -3160,7 +3105,6 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr 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) @@ -3170,7 +3114,6 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr g_error_free(error); return ret; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &ret); @@ -3222,7 +3165,6 @@ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase) 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) @@ -3232,7 +3174,6 @@ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase) g_error_free(error); return ret; - //LCOV_EXCL_STOP } if (parameters != NULL) { @@ -3340,13 +3281,13 @@ API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_set 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; } @@ -3400,13 +3341,13 @@ static int __add_mac_to_file(const char *filepath, const char *mac) 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; } @@ -3415,7 +3356,7 @@ static int __add_mac_to_file(const char *filepath, const char *mac) 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; } @@ -3597,7 +3538,6 @@ API int tethering_wifi_enable_dhcp(tethering_h tethering, bool 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) result = TETHERING_ERROR_PERMISSION_DENIED; @@ -3608,7 +3548,6 @@ API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable) th->dhcp_enabled = false; return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3646,7 +3585,6 @@ API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, c 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) @@ -3658,7 +3596,6 @@ API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, c th->dhcp_enabled = false; return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3704,11 +3641,9 @@ API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower) 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; } @@ -3723,6 +3658,8 @@ API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower) _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); @@ -3738,12 +3675,10 @@ API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower) 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; @@ -3769,7 +3704,6 @@ API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu) 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) @@ -3779,7 +3713,6 @@ API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu) g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3811,7 +3744,6 @@ API int tethering_wifi_change_mac(tethering_h tethering, char *mac) 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) @@ -3821,7 +3753,6 @@ API int tethering_wifi_change_mac(tethering_h tethering, char *mac) g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3884,7 +3815,6 @@ API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable 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) @@ -3894,7 +3824,6 @@ API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3912,8 +3841,14 @@ API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifn _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; @@ -3929,7 +3864,6 @@ API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifn 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) @@ -3939,7 +3873,6 @@ API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifn g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3949,7 +3882,7 @@ API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifn list = strdup(cmd); if (list == NULL) { - ERR("strdup failed\n"); //LCOV_EXCL_LINE + ERR("strdup failed\n"); return TETHERING_ERROR_OUT_OF_MEMORY; } @@ -3977,7 +3910,6 @@ API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering) 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) @@ -3987,7 +3919,6 @@ API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering) g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -3997,7 +3928,7 @@ API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering) 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); @@ -4048,7 +3979,6 @@ API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable) 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) @@ -4058,7 +3988,6 @@ API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable) g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -4093,7 +4022,6 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, 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) @@ -4103,7 +4031,6 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -4115,7 +4042,7 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, 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; } @@ -4150,7 +4077,6 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int 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) @@ -4160,7 +4086,6 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -4172,7 +4097,7 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int 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; } @@ -4211,7 +4136,7 @@ API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, voi 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); @@ -4248,7 +4173,6 @@ API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering 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) @@ -4258,7 +4182,6 @@ API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering g_error_free(error); return result; - //LCOV_EXCL_STOP } g_variant_get(parameters, "(u)", &result); @@ -4285,7 +4208,6 @@ API int tethering_wifi_push_wps_button(tethering_h tethering) 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) @@ -4295,7 +4217,6 @@ API int tethering_wifi_push_wps_button(tethering_h tethering) g_error_free(error); return ret; - //LCOV_EXCL_STOP } if (parameters != NULL) { @@ -4313,6 +4234,9 @@ API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin) _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; @@ -4323,7 +4247,6 @@ API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin) 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) @@ -4333,7 +4256,6 @@ API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin) g_error_free(error); return ret; - //LCOV_EXCL_STOP } if (parameters != NULL) { diff --git a/src/tethering_client.c b/src/tethering_client.c index ec4d7e2..efde31e 100755 --- a/src/tethering_client.c +++ b/src/tethering_client.c @@ -24,6 +24,8 @@ API int tethering_client_clone(tethering_client_h *dest, tethering_client_h orig _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; @@ -149,6 +151,9 @@ API int tethering_client_get_time(tethering_client_h client, time_t *timestamp) _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; diff --git a/src/tethering_private.c b/src/tethering_private.c index 5d11cb2..b169250 100755 --- a/src/tethering_private.c +++ b/src/tethering_private.c @@ -27,10 +27,8 @@ bool __check_feature_supported(const char *key, tethering_supported_feature_e fe { 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; @@ -64,12 +62,10 @@ int _tethering_check_feature_supported(const char* feature, ...) } 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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..6102477 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +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") diff --git a/tests/mocks/tethering_dummy_client.c b/tests/mocks/tethering_dummy_client.c new file mode 100644 index 0000000..cc24faf --- /dev/null +++ b/tests/mocks/tethering_dummy_client.c @@ -0,0 +1,58 @@ +/* +* 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 +#include +#include +#include + +#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); +} diff --git a/tests/mocks/tethering_dummy_client.h b/tests/mocks/tethering_dummy_client.h new file mode 100644 index 0000000..0c090ed --- /dev/null +++ b/tests/mocks/tethering_dummy_client.h @@ -0,0 +1,20 @@ +/* +* 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); diff --git a/tests/mocks/tethering_file.c b/tests/mocks/tethering_file.c new file mode 100644 index 0000000..7df2483 --- /dev/null +++ b/tests/mocks/tethering_file.c @@ -0,0 +1,70 @@ +/* + * 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 +#include +#include + +#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); +} diff --git a/tests/mocks/tethering_file.h b/tests/mocks/tethering_file.h new file mode 100644 index 0000000..eb582ea --- /dev/null +++ b/tests/mocks/tethering_file.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +void tethering_mock_set_file_result(bool result); diff --git a/tests/mocks/tethering_gdbus.c b/tests/mocks/tethering_gdbus.c new file mode 100644 index 0000000..ccb2f23 --- /dev/null +++ b/tests/mocks/tethering_gdbus.c @@ -0,0 +1,267 @@ +/* + * 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 +#include +#include +#include + +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; +} diff --git a/tests/mocks/tethering_gdbus.h b/tests/mocks/tethering_gdbus.h new file mode 100644 index 0000000..78da14d --- /dev/null +++ b/tests/mocks/tethering_gdbus.h @@ -0,0 +1,35 @@ +/* +* 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 + +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); diff --git a/tests/mocks/tethering_ioctl.c b/tests/mocks/tethering_ioctl.c new file mode 100644 index 0000000..5b50552 --- /dev/null +++ b/tests/mocks/tethering_ioctl.c @@ -0,0 +1,69 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#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; +} diff --git a/tests/mocks/tethering_memory.c b/tests/mocks/tethering_memory.c new file mode 100644 index 0000000..9bee67c --- /dev/null +++ b/tests/mocks/tethering_memory.c @@ -0,0 +1,47 @@ +/* + * 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 +#include +#include + +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; +} diff --git a/tests/mocks/tethering_memory.h b/tests/mocks/tethering_memory.h new file mode 100644 index 0000000..1fd6673 --- /dev/null +++ b/tests/mocks/tethering_memory.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +void tethering_mock_set_memory_result(bool result); diff --git a/tests/mocks/tethering_system_info.c b/tests/mocks/tethering_system_info.c new file mode 100644 index 0000000..9b37e77 --- /dev/null +++ b/tests/mocks/tethering_system_info.c @@ -0,0 +1,35 @@ +/* +* 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 +#include +#include +#include + +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; +} diff --git a/tests/mocks/tethering_system_info.h b/tests/mocks/tethering_system_info.h new file mode 100644 index 0000000..1609f8b --- /dev/null +++ b/tests/mocks/tethering_system_info.h @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include + +void tethering_mock_set_sysinfo_result(bool value); diff --git a/tests/mocks/tethering_vconf.c b/tests/mocks/tethering_vconf.c new file mode 100644 index 0000000..4f3c0ba --- /dev/null +++ b/tests/mocks/tethering_vconf.c @@ -0,0 +1,82 @@ +/* + * 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 + +#include +#include +#include + +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"); +} diff --git a/tests/mocks/tethering_vconf.h b/tests/mocks/tethering_vconf.h new file mode 100644 index 0000000..e59f06a --- /dev/null +++ b/tests/mocks/tethering_vconf.h @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include + +void tethering_mock_set_vconf_result(bool result); +void tethering_mock_set_enabled_state(bool usb, bool wifi, bool bluetooth, bool p2p); diff --git a/tests/tethering-gtest-client.cpp b/tests/tethering-gtest-client.cpp new file mode 100755 index 0000000..67d46f6 --- /dev/null +++ b/tests/tethering-gtest-client.cpp @@ -0,0 +1,169 @@ +/* +* 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 + +#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)); +} diff --git a/tests/tethering-gtest-common.cpp b/tests/tethering-gtest-common.cpp new file mode 100755 index 0000000..135f7a7 --- /dev/null +++ b/tests/tethering-gtest-common.cpp @@ -0,0 +1,378 @@ +/* +* 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 + +#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)); +} diff --git a/tests/tethering-gtest-main.cpp b/tests/tethering-gtest-main.cpp new file mode 100755 index 0000000..4890e9c --- /dev/null +++ b/tests/tethering-gtest-main.cpp @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/tethering-gtest-wifi.cpp b/tests/tethering-gtest-wifi.cpp new file mode 100755 index 0000000..c813f29 --- /dev/null +++ b/tests/tethering-gtest-wifi.cpp @@ -0,0 +1,802 @@ +/* +* 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 + +#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")); +} diff --git a/test/CMakeLists.txt b/tools/CMakeLists.txt similarity index 100% rename from test/CMakeLists.txt rename to tools/CMakeLists.txt diff --git a/test/tethering_test.c b/tools/tethering_test.c similarity index 100% rename from test/tethering_test.c rename to tools/tethering_test.c -- 2.7.4