Add gtest and mocks 09/236009/9
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 12 Jun 2020 02:33:42 +0000 (11:33 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 16 Jun 2020 03:07:56 +0000 (12:07 +0900)
This is the first draft for gtest.
The test cases for remaing API will be updated to another patch.

Change-Id: Ib8158a2cd991ad195a7969033ffa8876852085ab

18 files changed:
CMakeLists.txt
packaging/capi-network-softap.spec
test/CMakeLists.txt [deleted file]
test/softap_test.c [deleted file]
tests/CMakeLists.txt [new file with mode: 0644]
tests/mocks/softap_gdbus.c [new file with mode: 0644]
tests/mocks/softap_ioctl.c [new file with mode: 0644]
tests/mocks/softap_memory.c [new file with mode: 0644]
tests/mocks/softap_memory.h [new file with mode: 0644]
tests/mocks/softap_permission.c [new file with mode: 0644]
tests/mocks/softap_permission.h [new file with mode: 0644]
tests/mocks/softap_system_info.c [new file with mode: 0644]
tests/mocks/softap_system_info.h [new file with mode: 0644]
tests/mocks/softap_vconf.c [new file with mode: 0644]
tests/mocks/softap_vconf.h [new file with mode: 0644]
tests/softap_gtest.cpp [new file with mode: 0755]
tools/CMakeLists.txt [new file with mode: 0755]
tools/softap_test.c [new file with mode: 0755]

index 8110f78d0b74461a07ba7b8810c125c458000fa1..1980f8d60e47375ec602fd3422ebc2cb62f921b6 100755 (executable)
@@ -21,6 +21,7 @@ FOREACH(flag ${${fw_name}_CFLAGS})
 ENDFOREACH(flag)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
+#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11")
 
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 
@@ -58,36 +59,5 @@ CONFIGURE_FILE(
 )
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
-ADD_SUBDIRECTORY(test)
-
-IF(UNIX)
-
-ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
-ADD_CUSTOM_COMMAND(
-        DEPENDS clean
-        COMMENT "distribution clean"
-        COMMAND find
-        ARGS    .
-        -not -name config.cmake -and \(
-        -name tester.c -or
-        -name Testing -or
-        -name CMakeFiles -or
-        -name cmake.depends -or
-        -name cmake.check_depends -or
-        -name CMakeCache.txt -or
-        -name cmake.check_cache -or
-        -name *.cmake -or
-        -name Makefile -or
-        -name core -or
-        -name core.* -or
-        -name gmon.out -or
-        -name install_manifest.txt -or
-        -name *.pc -or
-        -name *~ \)
-        | grep -v TC | xargs rm -rf
-        TARGET  distclean
-        VERBATIM
-)
-
-ENDIF(UNIX)
-
+ADD_SUBDIRECTORY(tools)
+ADD_SUBDIRECTORY(tests)
index 31552dc56c0b7bc8c8ae141785070957f3e35df3..e2b3e08521a96aa33b2973bbb1671f866e8155be 100644 (file)
@@ -13,9 +13,11 @@ BuildRequires:       pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(gmock)
 BuildRequires: cmake
 %if 0%{?gcov:1}
 BuildRequires: lcov
+BuildRequires: tar
 %endif
 Requires(post):                /sbin/ldconfig
 Requires(postun):      /sbin/ldconfig
@@ -57,16 +59,21 @@ export LDFLAGS+=" -lgcov"
 %cmake .
 make %{?_smp_mflags}
 
+%install
+%make_install
+
 %if 0%{?gcov:1}
-mkdir -p gcov-obj
-find . -name '*.gcno' ! -iname "*client*" ! -iname "*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
+%check
+tests/softap-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/test/CMakeLists.txt b/test/CMakeLists.txt
deleted file mode 100755 (executable)
index f42ed85..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-SET(fw_test "${fw_name}_test")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0)
-FOREACH(flag ${${fw_test}_CFLAGS})
-    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-aux_source_directory(. sources)
-FOREACH(src ${sources})
-    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
-    MESSAGE("${src_name}")
-    ADD_EXECUTABLE(${src_name} ${src})
-    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
-ENDFOREACH()
-
-INSTALL(TARGETS softap_test RUNTIME DESTINATION bin/)
diff --git a/test/softap_test.c b/test/softap_test.c
deleted file mode 100755 (executable)
index 4699caf..0000000
+++ /dev/null
@@ -1,821 +0,0 @@
-/*
-* Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib-object.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <vconf.h>
-#include <time.h>
-
-#include "softap.h"
-
-#define DISABLE_REASON_TEXT_LEN        64
-#define COMMON_STR_BUF_LEN     32
-
-gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
-
-softap_h sa = NULL;
-
-static const char *__convert_disabled_code_to_string(const softap_disabled_cause_e code)
-{
-       static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
-
-       switch (code) {
-       case SOFTAP_DISABLED_BY_FLIGHT_MODE:
-               strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_LOW_BATTERY:
-               strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_NETWORK_CLOSE:
-               strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_TIMEOUT:
-               strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_OTHERS:
-               strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_REQUEST:
-               strncpy(str_buf, "disabled by my request", sizeof(str_buf));
-               break;
-
-       case SOFTAP_DISABLED_BY_WIFI_ON:
-               strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
-               break;
-
-       default:
-               strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
-               break;
-       }
-
-       return str_buf;
-}
-
-/* Callback functions */
-static void __enabled_cb(softap_error_e error, bool is_requested, void *data)
-{
-       if (error != SOFTAP_ERROR_NONE) {
-               if (!is_requested)
-                       return;
-
-               printf("Soft AP is not enabled. error code[0x%X]\n", error);
-               return;
-       }
-
-       if (is_requested)
-               printf("Soft AP is enabled successfully\n");
-       else
-               printf("Soft AP is enabled by other app\n");
-
-       return;
-}
-
-static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, void *data)
-{
-       if (error != SOFTAP_ERROR_NONE) {
-               if (code != SOFTAP_DISABLED_BY_REQUEST)
-                       return;
-
-               printf("Soft AP is not disabled. error code[0x%X]\n", error);
-               return;
-       }
-
-       printf("Soft AP is %s\n", __convert_disabled_code_to_string(code));
-
-       return;
-}
-
-static void __settings_reloaded_cb(softap_error_e result, void *user_data)
-{
-       g_print("__settings_reloaded_cb\n");
-
-       if (result != SOFTAP_ERROR_NONE) {
-               g_print("softap_reload_settings is failed. error[0x%X]\n", result);
-               return;
-       }
-
-       printf("## Soft AP setting is reloaded\n");
-
-       return;
-}
-
-static void __security_changed_cb(softap_security_type_e changed_type, void *user_data)
-{
-       g_print("Security type is changed to [%d]\n", changed_type);
-
-       return;
-}
-
-static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
-{
-       g_print("SSID visibility is changed to [%s]\n",
-                       changed_visible ? "visible" : "invisible");
-       return;
-}
-
-static void __passphrase_changed_cb(void *user_data)
-{
-
-       g_print("Passphrase is changed\n");
-}
-
-static bool __clients_foreach_cb(softap_client_h client, void *data)
-{
-       softap_client_h clone = NULL;
-       char *ip_address = NULL;
-       char *mac_address = NULL;
-       char *hostname = NULL;
-       time_t timestamp;
-       struct tm t;
-
-       /* Clone internal information */
-       if (softap_client_clone(&clone, client) != SOFTAP_ERROR_NONE) {
-               g_print("softap_client_clone is failed\n");
-               return false;
-       }
-
-       /* Get information */
-       if (softap_client_get_ip_address(clone, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address) != SOFTAP_ERROR_NONE)
-               g_print("softap_client_get_ip_address is failed\n");
-
-       if (softap_client_get_mac_address(clone, &mac_address) != SOFTAP_ERROR_NONE)
-               g_print("softap_client_get_mac_address is failed\n");
-
-       if (softap_client_get_name(clone, &hostname) != SOFTAP_ERROR_NONE)
-               g_print("softap_client_get_hostname is failed\n");
-
-       if (softap_client_get_time(clone, &timestamp) != SOFTAP_ERROR_NONE)
-               g_print("softap_client_get_hostname is failed\n");
-       /* End of getting information */
-
-       localtime_r(&timestamp, &t);
-
-       g_print("\n< Client Info. >\n");
-       g_print("\tIP Address %s\n", ip_address);
-       g_print("\tMAC Address : %s\n", mac_address);
-       g_print("\tHostname : %s\n", hostname);
-       g_print("\tTime stamp : %04d-%02d-%02d %02d:%02d:%02d\n",
-                       t.tm_year + 1900, t.tm_mon + 1,
-                       t.tm_mday, t.tm_hour,
-                       t.tm_min, t.tm_sec);
-
-       /* Destroy cloned objects */
-       if (ip_address)
-               free(ip_address);
-       if (mac_address)
-               free(mac_address);
-       if (hostname)
-               free(hostname);
-
-       softap_client_destroy(clone);
-
-       /* Continue iteration */
-       return true;
-}
-
-static void __connection_state_changed_cb(softap_client_h client, bool open, void *data)
-{
-       softap_client_h clone = NULL;
-       char *ip_address = NULL;
-       char *mac_address = NULL;
-       char *hostname = NULL;
-
-       softap_client_clone(&clone, client);
-       if (clone == NULL) {
-               g_print("tetheirng_client_clone is failed\n");
-               return;
-       }
-
-       softap_client_get_ip_address(clone,
-                       SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
-       softap_client_get_mac_address(clone, &mac_address);
-       softap_client_get_name(clone, &hostname);
-
-       if (open) {
-               g_print("## New station IP [%s], MAC [%s], hostname [%s]\n",
-                               ip_address, mac_address, hostname);
-       } else {
-               g_print("## Disconnected station IP [%s], MAC [%s], hostname [%s]\n",
-                               ip_address, mac_address, hostname);
-       }
-
-       if (ip_address)
-               free(ip_address);
-       if (mac_address)
-               free(mac_address);
-       if (hostname)
-               free(hostname);
-
-       softap_client_destroy(clone);
-
-       return;
-}
-
-static void __register_cbs(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-
-       ret = softap_set_enabled_cb(sa, __enabled_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set enabled callback!!\n");
-
-       ret = softap_set_disabled_cb(sa, __disabled_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set disabled callback!!\n");
-
-       ret = softap_set_security_type_changed_cb(sa, __security_changed_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set security changed callback!!\n");
-
-       ret = softap_set_ssid_visibility_changed_cb(sa, __ssid_visibility_changed_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set visibility changed callback!!\n");
-
-       ret = softap_set_passphrase_changed_cb(sa, __passphrase_changed_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set passphrase changed callback!!\n");
-
-       ret = softap_set_client_connection_state_changed_cb(sa, __connection_state_changed_cb, NULL);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set client connection state changed callback!!\n");
-
-       return;
-}
-
-static void __deregister_cbs(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-
-       ret = softap_unset_enabled_cb(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to unset enabled callback!!\n");
-
-       ret = softap_unset_disabled_cb(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to unset disabled callback!!\n");
-
-       ret = softap_unset_security_type_changed_cb(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to unset security changed callback!!\n");
-
-       ret = softap_unset_ssid_visibility_changed_cb(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to unset visibility changed callback!!\n");
-
-       ret = softap_unset_client_connection_state_changed_cb(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to unset client connection state changed callback!!\n");
-
-       return;
-}
-
-
-static int test_softap_create(void)
-{
-       softap_create(&sa);
-       __register_cbs();
-
-       return 1;
-}
-
-static int test_softap_destroy(void)
-{
-       __deregister_cbs();
-       softap_destroy(sa);
-       sa = NULL;
-
-       return 1;
-}
-
-static int test_softap_enable(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-
-       ret = softap_enable(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_disable(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-
-       ret = softap_disable(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_is_enabled(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-       bool enabled = false;
-
-       ret = softap_is_enabled(sa, &enabled);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       printf("Soft AP is %s\n", enabled ? "enabled" : "disabled");
-
-       return 1;
-}
-
-static int test_softap_get_settings(void)
-{
-       int ret = SOFTAP_ERROR_NONE;
-       char *ssid = NULL;
-       char *passphrase = NULL;
-       char *mac_address = NULL;
-       char *interface_name = NULL;
-       char *ip_address = NULL;
-       char *gateway_address = NULL;
-       char *subnet_mask = NULL;
-       char *vendor = NULL;
-       bool visible = false;
-       bool dhcp_enabled = false;
-       softap_security_type_e security_type = SOFTAP_SECURITY_TYPE_NONE;
-       softap_wireless_mode_e mode = SOFTAP_WIRELESS_MODE_G;
-       int channel;
-
-       ret = softap_get_ssid(sa, &ssid);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get ssid\n");
-
-       ret = softap_get_passphrase(sa, &passphrase);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get passphrase\n");
-
-       ret = softap_get_ssid_visibility(sa, &visible);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get ssid visibility\n");
-
-       ret = softap_get_security_type(sa, &security_type);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get security type\n");
-
-       ret = softap_get_channel(sa, &channel);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get channel\n");
-
-       ret = softap_get_mode(sa, &mode);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get mode\n");
-
-       ret = softap_get_mac_address(sa, &mac_address);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get mac address\n");
-
-       ret = softap_get_network_interface_name(sa, &interface_name);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get interface name\n");
-
-       ret = softap_get_ip_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get IP address\n");
-
-       ret = softap_get_gateway_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway_address);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get gateway address\n");
-
-       ret = softap_get_subnet_mask(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &subnet_mask);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get subnet mask\n");
-
-       ret = softap_get_vendor_element(sa, &vendor);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get vendor element\n");
-
-       ret = softap_is_dhcp_enabled(sa, &dhcp_enabled);
-       if (ret != SOFTAP_ERROR_NONE)
-               printf("Failed to get dhcp state\n");
-
-       printf("* SSID: %s\n", ssid);
-       printf("* SSID visibility: %d\n", visible);
-       printf("* Security type: %d\n", security_type);
-       printf("* Passphrase: %s\n", passphrase);
-       printf("* Channel: %d\n", channel);
-       printf("* Mode: %d\n", mode);
-       printf("* MAC address: %s\n", mac_address);
-       printf("* Network Interface: %s\n", interface_name);
-       printf("* IP address: %s\n", ip_address);
-       printf("* Gateway address: %s\n", gateway_address);
-       printf("* Subnetmask: %s\n", subnet_mask);
-       printf("* Vendor element: %s\n", vendor);
-       printf("* DHCP: %s\n", (dhcp_enabled ? "enabled" : "disabled"));
-
-       if (ssid) g_free(ssid);
-       if (passphrase) g_free(passphrase);
-       if (mac_address) g_free(mac_address);
-       if (interface_name)     g_free(interface_name);
-       if (ip_address) g_free(ip_address);
-       if (gateway_address) g_free(gateway_address);
-       if (subnet_mask) g_free(subnet_mask);
-       if (vendor) g_free(vendor);
-
-       return 1;
-}
-
-static int test_softap_set_ssid(void)
-{
-       int ret;
-       char ssid[100];
-
-       printf("Input SSID for Softap: ");
-       ret = scanf("%99s", ssid);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-
-       ret = softap_set_ssid(sa, ssid);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_ssid_visibility(void)
-{
-       int ret;
-       int visibility;
-
-       printf("Input visibility for Soft AP (0:invisible, 1:visible)");
-       ret = scanf("%9d", &visibility);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-
-       ret = softap_set_ssid_visibility(sa, visibility);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_security_type(void)
-{
-       int ret;
-       int security_type;
-
-       printf("Input security type for Soft AP (0:NONE, 1:WPA2_PSK, 2:WPS)");
-       ret = scanf("%9d", &security_type);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return -1;
-       }
-
-       ret = softap_set_security_type(sa, security_type);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_passphrase(void)
-{
-       int ret;
-       char passphrase[65];
-
-       printf("Input passphrase for Softap: ");
-       ret = scanf("%64s", passphrase);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-
-       ret = softap_set_passphrase(sa, passphrase);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_vendor_element(void)
-{
-       int ret;
-       char vendor[1024];
-
-       printf("Input vendor elements(e.g. DD050016328000, DD050016321000): ");
-       ret = scanf("%1023s", vendor);
-
-       ret = softap_set_vendor_element(sa, vendor);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_channel(void)
-{
-       int ret;
-       int channel;
-
-       printf("Input channel for Soft AP: ");
-       ret = scanf("%9d", &channel);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return -1;
-       }
-
-       ret = softap_set_channel(sa, channel);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_reload_settings(void)
-{
-       int ret = softap_reload_settings(sa, __settings_reloaded_cb, NULL);
-
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_get_client_info(void)
-{
-       int ret;
-
-       ret = softap_foreach_connected_clients(sa, __clients_foreach_cb, NULL);
-
-       if (ret != SOFTAP_ERROR_NONE)
-                       return 0;
-
-       return 1;
-}
-
-static int test_softap_push_wps_button(void)
-{
-       int ret;
-
-       ret = softap_push_wps_button(sa);
-
-       if (ret != SOFTAP_ERROR_NONE)
-                       return 0;
-
-       return 1;
-}
-
-static int test_softap_set_wps_pin(void)
-{
-       int ret;
-       char wps_pin[128];
-
-       printf("Input WPS PIN: ");
-       ret = scanf("%127s", wps_pin);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-       ret = softap_set_wps_pin(sa, wps_pin);
-
-       if (ret != SOFTAP_ERROR_NONE)
-                       return 0;
-
-       return 1;
-}
-
-static int test_softap_enable_dhcp(void)
-{
-       int ret;
-       int enable_type;
-       char rangestart[16];
-       char rangestop[16];
-
-       printf("Enable with range? (0. no, 1. yes): ");
-       ret = scanf("%d", &enable_type);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-
-       if (enable_type) {
-               printf("Input DHCP range\n");
-               printf("Start: ");
-               ret = scanf("%15s", rangestart);
-               if (ret < 0) {
-                       printf("scanf is failed!!\n");
-                       return 0;
-               }
-
-               printf("Stop: ");
-               ret = scanf("%15s", rangestop);
-               if (ret < 0) {
-                       printf("scanf is failed!!\n");
-                       return 0;
-               }
-
-               ret = softap_enable_dhcp_with_range(sa, rangestart, rangestop);
-               if (ret != SOFTAP_ERROR_NONE)
-                       return 0;
-       } else {
-               ret = softap_enable_dhcp(sa);
-               if (ret != SOFTAP_ERROR_NONE)
-                       return 0;
-       }
-
-       return 1;
-}
-
-static int test_softap_disable_dhcp(void)
-{
-       int ret;
-
-       ret = softap_disable_dhcp(sa);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_mode(void)
-{
-       int ret;
-       int type;
-
-       printf("Input wireless for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
-       ret = scanf("%d", &type);
-
-       ret = softap_set_mode(sa, type);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-static int test_softap_set_ip_address(void)
-{
-       int ret;
-       char ip[16];
-
-       printf("Input IP address for Softap(IPv4 only): ");
-       ret = scanf("%15s", ip);
-       if (ret < 0) {
-               printf("scanf is failed!!\n");
-               return 0;
-       }
-
-       ret = softap_set_ip_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, ip);
-       if (ret != SOFTAP_ERROR_NONE)
-               return 0;
-
-       return 1;
-}
-
-int main(int argc, char **argv)
-{
-       GMainLoop *mainloop;
-
-#if !GLIB_CHECK_VERSION(2, 36, 0)
-       g_type_init();
-#endif
-       mainloop = g_main_loop_new(NULL, false);
-
-       GIOChannel *channel = g_io_channel_unix_new(0);
-       g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
-       printf("Test Thread created...\n");
-       g_main_loop_run(mainloop);
-
-       return 0;
-}
-
-gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
-{
-       int rv;
-       char a[10];
-
-       printf("Event received from stdin\n");
-
-       rv = read(0, a, 10);
-
-       if (rv <= 0 || a[0] == '0')
-               exit(1);
-
-       if (a[0] == '\n' || a[0] == '\r') {
-               printf("\n\n Network Connection API Test App\n\n");
-               printf("Options..\n");
-               printf("1       - SoftAP create and set callbacks\n");
-               printf("2       - SoftAP destroy\n");
-               printf("3       - SoftAP enable\n");
-               printf("4       - SoftAP disable\n");
-               printf("5       - Is Soft AP enabled?\n");
-               printf("6       - Get Soft AP settings\n");
-               printf("7       - Set Soft AP SSID\n");
-               printf("8       - Set Soft AP SSID visibility\n");
-               printf("9       - Set Soft AP security type\n");
-               printf("a       - Set Soft AP passpharse\n");
-               printf("b       - Set Soft AP vendor element\n");
-               printf("c       - Set Soft AP channel\n");
-               printf("d       - Get Soft AP client information\n");
-               printf("e       - SoftAP reload settings\n");
-               printf("f       - Push WPS Button (WPS PBC)\n");
-               printf("g       - Set WPS PIN\n");
-               printf("h       - Enable DHCP Server\n");
-               printf("i       - Disable DHCP Server\n");
-               printf("j       - Set wireless mode\n");
-               printf("k       - Set IP address (IPv4 only)\n");
-               printf("0       - Exit \n");
-               printf("ENTER  - Show options menu.......\n");
-       }
-
-       switch (a[0]) {
-       case '1':
-               rv = test_softap_create();
-               break;
-       case '2':
-               rv = test_softap_destroy();
-               break;
-       case '3':
-               rv = test_softap_enable();
-               break;
-       case '4':
-               rv = test_softap_disable();
-               break;
-       case '5':
-               rv = test_softap_is_enabled();
-               break;
-       case '6':
-               rv = test_softap_get_settings();
-               break;
-       case '7':
-               rv = test_softap_set_ssid();
-               break;
-       case '8':
-               rv = test_softap_set_ssid_visibility();
-               break;
-       case '9':
-               rv = test_softap_set_security_type();
-               break;
-       case 'a':
-               rv = test_softap_set_passphrase();
-               break;
-       case 'b':
-               rv = test_softap_set_vendor_element();
-               break;
-       case 'c':
-               rv = test_softap_set_channel();
-               break;
-       case 'd':
-               rv = test_softap_get_client_info();
-               break;
-       case 'e':
-               rv = test_softap_reload_settings();
-               break;
-       case 'f':
-               rv = test_softap_push_wps_button();
-               break;
-       case 'g':
-               rv = test_softap_set_wps_pin();
-               break;
-       case 'h':
-               rv = test_softap_enable_dhcp();
-               break;
-       case 'i':
-               rv = test_softap_disable_dhcp();
-               break;
-       case 'j':
-               rv = test_softap_set_mode();
-               break;
-       case 'k':
-               rv = test_softap_set_ip_address();
-               break;
-       }
-
-       if (rv == 1)
-               printf("Operation succeeded!\n");
-       else
-               printf("Operation failed!\n");
-
-       return true;
-}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4d6add6
--- /dev/null
@@ -0,0 +1,25 @@
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+ADD_DEFINITIONS("-DSOFTAP_GTEST")
+
+pkg_check_modules(gtest_pkgs REQUIRED gmock)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(SOFTAP_GTEST "softap-gtest")
+FILE(GLOB GTEST_SRCS *.cpp mocks/*.c ${CMAKE_SOURCE_DIR}/src/*.c)
+ADD_EXECUTABLE(${SOFTAP_GTEST} ${GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${SOFTAP_GTEST} ${gtest_pkgs_LIBRARIES} ${${fw_name}_LIBRARIES})
+SET_TARGET_PROPERTIES(${SOFTAP_GTEST} PROPERTIES
+       COMPILE_FLAGS "-fPIE"
+       LINK_FLAGS "-Wl,\
+--wrap=malloc,\
+--wrap=calloc,\
+--wrap=g_cancellable_new,\
+--wrap=g_bus_get_sync,\
+--wrap=g_dbus_proxy_new_sync,\
+--wrap=g_dbus_connection_signal_subscribe,\
+--wrap=g_dbus_connection_signal_unsubscribe,\
+--wrap=ioctl,\
+--wrap=cynara_check,\
+--wrap=system_info_get_platform_bool,\
+--wrap=vconf_get_int")
diff --git a/tests/mocks/softap_gdbus.c b/tests/mocks/softap_gdbus.c
new file mode 100644 (file)
index 0000000..9c394ff
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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 <stdio.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+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)
+{
+       return 1;
+}
+
+void __wrap_g_dbus_connection_signal_unsubscribe(GDBusConnection *connection,
+               guint subscription_id)
+{
+       return;
+}
diff --git a/tests/mocks/softap_ioctl.c b/tests/mocks/softap_ioctl.c
new file mode 100644 (file)
index 0000000..c0e92fd
--- /dev/null
@@ -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 <arpa/inet.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#define SOFTAP_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(SOFTAP_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/softap_memory.c b/tests/mocks/softap_memory.c
new file mode 100644 (file)
index 0000000..a8cd5cd
--- /dev/null
@@ -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 "softap_memory.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+static bool softap_mock_memory_result;
+
+extern void *__real_malloc(size_t size);
+extern void *__real_calloc(size_t nmemb, size_t size);
+
+void softap_mock_set_memory_result(bool result)
+{
+       softap_mock_memory_result = result;
+}
+
+void *__wrap_malloc(size_t size)
+{
+       if (softap_mock_memory_result)
+               return __real_malloc(size);
+
+       return NULL;
+}
+
+void *__wrap_calloc(size_t nmemb, size_t size)
+{
+       if (softap_mock_memory_result)
+               return __real_calloc(nmemb, size);
+
+       return NULL;
+}
diff --git a/tests/mocks/softap_memory.h b/tests/mocks/softap_memory.h
new file mode 100644 (file)
index 0000000..d759611
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+
+void softap_mock_set_memory_result(bool result);
diff --git a/tests/mocks/softap_permission.c b/tests/mocks/softap_permission.c
new file mode 100644 (file)
index 0000000..f7ff514
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+* 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 "softap_permission.h"
+
+#include "softap.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <cynara-client.h>
+
+static bool softap_mock_permission;
+
+void softap_mock_set_permission(bool value)
+{
+       softap_mock_permission = value;
+}
+
+int __wrap_cynara_check(cynara *p_cynara,
+               const char *client, const char *client_session,
+               const char *user, const char *privilege)
+{
+       if (!p_cynara || !client || !client_session || !user || !privilege)
+               return CYNARA_API_INVALID_PARAM;
+
+       return softap_mock_permission ? CYNARA_API_ACCESS_ALLOWED : CYNARA_API_ACCESS_DENIED;
+}
diff --git a/tests/mocks/softap_permission.h b/tests/mocks/softap_permission.h
new file mode 100644 (file)
index 0000000..daee49a
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+
+void softap_mock_set_permission(bool value);
diff --git a/tests/mocks/softap_system_info.c b/tests/mocks/softap_system_info.c
new file mode 100644 (file)
index 0000000..27cc4b6
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+* 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 "softap_system_info.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <system_info.h>
+
+#define SOFTAP_FEATURE "http://tizen.org/feature/network.wifi.softap"
+
+static bool softap_mock_sysinfo_result;
+extern int __real_system_info_get_platform_bool(const char *key, bool *value);
+
+void softap_mock_set_sysinfo_result(bool value)
+{
+       softap_mock_sysinfo_result = value;
+}
+
+int __wrap_system_info_get_platform_bool(const char *key, bool *value)
+{
+       if (0 == strcmp(key, SOFTAP_FEATURE)) {
+               *value = softap_mock_sysinfo_result;
+               return SYSTEM_INFO_ERROR_NONE;
+       }
+
+       return __real_system_info_get_platform_bool(key, value);
+}
diff --git a/tests/mocks/softap_system_info.h b/tests/mocks/softap_system_info.h
new file mode 100644 (file)
index 0000000..4350184
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+
+void softap_mock_set_sysinfo_result(bool value);
diff --git a/tests/mocks/softap_vconf.c b/tests/mocks/softap_vconf.c
new file mode 100644 (file)
index 0000000..ee0f006
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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 "softap_memory.h"
+
+#include <vconf.h>
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+static bool softap_mock_vconf_result;
+static bool softap_mock_enabled_state;
+
+extern int __real_vconf_get_int(const char *in_key, int *intval);
+
+void softap_mock_set_vconf_result(bool result)
+{
+       softap_mock_vconf_result = result;
+}
+
+void softap_mock_set_enabled_state(bool enable)
+{
+       softap_mock_enabled_state = enable;
+}
+
+int __wrap_vconf_get_int(const char *in_key, int *intval)
+{
+       if (!softap_mock_vconf_result)
+               return __real_vconf_get_int(in_key, intval);
+
+       if (softap_mock_enabled_state
+                       && strncmp(in_key, VCONFKEY_MOBILE_HOTSPOT_MODE,
+                               strlen(VCONFKEY_MOBILE_HOTSPOT_MODE)) == 0)
+               *intval |= VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
+
+       return 0;
+}
diff --git a/tests/mocks/softap_vconf.h b/tests/mocks/softap_vconf.h
new file mode 100644 (file)
index 0000000..43ba72a
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+
+void softap_mock_set_vconf_result(bool result);
+void softap_mock_set_enabled_state(bool enable);
diff --git a/tests/softap_gtest.cpp b/tests/softap_gtest.cpp
new file mode 100755 (executable)
index 0000000..d21b9ef
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <gtest/gtest.h>
+
+#include "softap.h"
+
+extern "C" {
+#include "mocks/softap_memory.h"
+#include "mocks/softap_system_info.h"
+#include "mocks/softap_permission.h"
+#include "mocks/softap_vconf.h"
+}
+
+class SoftApTest: public ::testing::Test {
+       protected:
+               softap_h handle;
+
+               void SetUp() override
+               {
+                       softap_mock_set_memory_result(true);
+                       softap_mock_set_sysinfo_result(true);
+                       softap_mock_set_permission(true);
+                       softap_mock_set_vconf_result(true);
+                       softap_create(&handle);
+               }
+
+               void TearDown() override
+               {
+                       softap_destroy(handle);
+                       softap_mock_set_vconf_result(false);
+                       softap_mock_set_permission(false);
+                       softap_mock_set_sysinfo_result(false);
+                       softap_mock_set_memory_result(true);
+               }
+};
+
+TEST_F(SoftApTest, CreateHandleN)
+{
+       softap_h test_handle = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_create(NULL));
+
+       softap_mock_set_memory_result(false);
+       EXPECT_EQ(SOFTAP_ERROR_OUT_OF_MEMORY, softap_create(&test_handle));
+}
+
+TEST_F(SoftApTest, CreateHandleP)
+{
+       softap_h test_handle = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_NONE, softap_create(&test_handle));
+
+       softap_destroy(test_handle);
+}
+
+TEST_F(SoftApTest, DestroyHandleN)
+{
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_destroy(NULL));
+}
+
+TEST_F(SoftApTest, DestroyHandleP)
+{
+       softap_h test_handle = NULL;
+
+       softap_create(&test_handle);
+       EXPECT_EQ(SOFTAP_ERROR_NONE, softap_destroy(test_handle));
+}
+
+TEST_F(SoftApTest, IsEnabledN)
+{
+       bool enable = false;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_is_enabled(NULL, &enable));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_is_enabled(handle, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_is_enabled(NULL, NULL));
+
+       softap_mock_set_vconf_result(false);
+       EXPECT_EQ(SOFTAP_ERROR_OPERATION_FAILED, softap_is_enabled(handle, &enable));
+}
+
+TEST_F(SoftApTest, IsEnabledP)
+{
+       bool enable = false;
+
+       EXPECT_EQ(SOFTAP_ERROR_NONE, softap_is_enabled(handle, &enable));
+}
+
+TEST_F(SoftApTest, GetMacAddressN)
+{
+       char *mac = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_get_mac_address(NULL, &mac));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_get_mac_address(handle, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER, softap_get_mac_address(NULL, NULL));
+
+       softap_mock_set_enabled_state(false);
+       EXPECT_EQ(SOFTAP_ERROR_NOT_PERMITTED, softap_get_mac_address(handle, &mac));
+
+       softap_mock_set_vconf_result(false);
+       EXPECT_EQ(SOFTAP_ERROR_OPERATION_FAILED, softap_get_mac_address(handle, &mac));
+}
+
+TEST_F(SoftApTest, GetMacAddressP)
+{
+       char *mac = NULL;
+
+       softap_mock_set_enabled_state(true);
+       EXPECT_EQ(SOFTAP_ERROR_NONE, softap_get_mac_address(handle, &mac));
+}
+
+TEST_F(SoftApTest, SetIpAddressN)
+{
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_set_ip_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, "192.168.0.1"));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_set_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_set_ip_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_set_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, "..."));
+       EXPECT_EQ(SOFTAP_ERROR_NOT_SUPPORTED,
+                       softap_set_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV6, "2001::23"));
+}
+
+TEST_F(SoftApTest, SetIpAddressP)
+{
+       EXPECT_EQ(SOFTAP_ERROR_NONE,
+                       softap_set_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, "192.168.0.1"));
+}
+
+TEST_F(SoftApTest, GetIpAddressN)
+{
+       char *ip = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_ip_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, &ip));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_ip_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+
+       softap_mock_set_enabled_state(false);
+       EXPECT_EQ(SOFTAP_ERROR_NOT_PERMITTED,
+                       softap_get_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &ip));
+}
+
+TEST_F(SoftApTest, GetIpAddressP)
+{
+       char *ip = NULL;
+
+       softap_mock_set_enabled_state(true);
+       EXPECT_EQ(SOFTAP_ERROR_NONE, softap_get_ip_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &ip));
+}
+
+TEST_F(SoftApTest, GetGatewayAddressN)
+{
+       char *gateway = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_gateway_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_gateway_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_gateway_address(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+
+       softap_mock_set_enabled_state(false);
+       EXPECT_EQ(SOFTAP_ERROR_NOT_PERMITTED,
+                       softap_get_gateway_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway));
+}
+
+TEST_F(SoftApTest, GetGatewayAddressP)
+{
+       char *gateway = NULL;
+
+       softap_mock_set_enabled_state(true);
+       EXPECT_EQ(SOFTAP_ERROR_NONE,
+                       softap_get_gateway_address(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway));
+}
+
+TEST_F(SoftApTest, GetSubnetMaskN)
+{
+       char *subnetmask = NULL;
+
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_subnet_mask(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, &subnetmask));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_subnet_mask(handle, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+       EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+                       softap_get_subnet_mask(NULL, SOFTAP_ADDRESS_FAMILY_IPV4, NULL));
+
+       softap_mock_set_enabled_state(false);
+       EXPECT_EQ(SOFTAP_ERROR_NOT_PERMITTED,
+                       softap_get_subnet_mask(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &subnetmask));
+}
+
+TEST_F(SoftApTest, GetSubnetMaskP)
+{
+       char *subnetmask = NULL;
+
+       softap_mock_set_enabled_state(true);
+       EXPECT_EQ(SOFTAP_ERROR_NONE,
+                       softap_get_subnet_mask(handle, SOFTAP_ADDRESS_FAMILY_IPV4, &subnetmask));
+}
+
+int main(int argc, char **argv)
+{
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..f42ed85
--- /dev/null
@@ -0,0 +1,20 @@
+SET(fw_test "${fw_name}_test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0)
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${src_name} ${src})
+    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
+
+INSTALL(TARGETS softap_test RUNTIME DESTINATION bin/)
diff --git a/tools/softap_test.c b/tools/softap_test.c
new file mode 100755 (executable)
index 0000000..4699caf
--- /dev/null
@@ -0,0 +1,821 @@
+/*
+* Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <vconf.h>
+#include <time.h>
+
+#include "softap.h"
+
+#define DISABLE_REASON_TEXT_LEN        64
+#define COMMON_STR_BUF_LEN     32
+
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
+
+softap_h sa = NULL;
+
+static const char *__convert_disabled_code_to_string(const softap_disabled_cause_e code)
+{
+       static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
+
+       switch (code) {
+       case SOFTAP_DISABLED_BY_FLIGHT_MODE:
+               strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_LOW_BATTERY:
+               strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_NETWORK_CLOSE:
+               strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_TIMEOUT:
+               strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_OTHERS:
+               strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_REQUEST:
+               strncpy(str_buf, "disabled by my request", sizeof(str_buf));
+               break;
+
+       case SOFTAP_DISABLED_BY_WIFI_ON:
+               strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
+               break;
+
+       default:
+               strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
+               break;
+       }
+
+       return str_buf;
+}
+
+/* Callback functions */
+static void __enabled_cb(softap_error_e error, bool is_requested, void *data)
+{
+       if (error != SOFTAP_ERROR_NONE) {
+               if (!is_requested)
+                       return;
+
+               printf("Soft AP is not enabled. error code[0x%X]\n", error);
+               return;
+       }
+
+       if (is_requested)
+               printf("Soft AP is enabled successfully\n");
+       else
+               printf("Soft AP is enabled by other app\n");
+
+       return;
+}
+
+static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, void *data)
+{
+       if (error != SOFTAP_ERROR_NONE) {
+               if (code != SOFTAP_DISABLED_BY_REQUEST)
+                       return;
+
+               printf("Soft AP is not disabled. error code[0x%X]\n", error);
+               return;
+       }
+
+       printf("Soft AP is %s\n", __convert_disabled_code_to_string(code));
+
+       return;
+}
+
+static void __settings_reloaded_cb(softap_error_e result, void *user_data)
+{
+       g_print("__settings_reloaded_cb\n");
+
+       if (result != SOFTAP_ERROR_NONE) {
+               g_print("softap_reload_settings is failed. error[0x%X]\n", result);
+               return;
+       }
+
+       printf("## Soft AP setting is reloaded\n");
+
+       return;
+}
+
+static void __security_changed_cb(softap_security_type_e changed_type, void *user_data)
+{
+       g_print("Security type is changed to [%d]\n", changed_type);
+
+       return;
+}
+
+static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
+{
+       g_print("SSID visibility is changed to [%s]\n",
+                       changed_visible ? "visible" : "invisible");
+       return;
+}
+
+static void __passphrase_changed_cb(void *user_data)
+{
+
+       g_print("Passphrase is changed\n");
+}
+
+static bool __clients_foreach_cb(softap_client_h client, void *data)
+{
+       softap_client_h clone = NULL;
+       char *ip_address = NULL;
+       char *mac_address = NULL;
+       char *hostname = NULL;
+       time_t timestamp;
+       struct tm t;
+
+       /* Clone internal information */
+       if (softap_client_clone(&clone, client) != SOFTAP_ERROR_NONE) {
+               g_print("softap_client_clone is failed\n");
+               return false;
+       }
+
+       /* Get information */
+       if (softap_client_get_ip_address(clone, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_ip_address is failed\n");
+
+       if (softap_client_get_mac_address(clone, &mac_address) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_mac_address is failed\n");
+
+       if (softap_client_get_name(clone, &hostname) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_hostname is failed\n");
+
+       if (softap_client_get_time(clone, &timestamp) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_hostname is failed\n");
+       /* End of getting information */
+
+       localtime_r(&timestamp, &t);
+
+       g_print("\n< Client Info. >\n");
+       g_print("\tIP Address %s\n", ip_address);
+       g_print("\tMAC Address : %s\n", mac_address);
+       g_print("\tHostname : %s\n", hostname);
+       g_print("\tTime stamp : %04d-%02d-%02d %02d:%02d:%02d\n",
+                       t.tm_year + 1900, t.tm_mon + 1,
+                       t.tm_mday, t.tm_hour,
+                       t.tm_min, t.tm_sec);
+
+       /* Destroy cloned objects */
+       if (ip_address)
+               free(ip_address);
+       if (mac_address)
+               free(mac_address);
+       if (hostname)
+               free(hostname);
+
+       softap_client_destroy(clone);
+
+       /* Continue iteration */
+       return true;
+}
+
+static void __connection_state_changed_cb(softap_client_h client, bool open, void *data)
+{
+       softap_client_h clone = NULL;
+       char *ip_address = NULL;
+       char *mac_address = NULL;
+       char *hostname = NULL;
+
+       softap_client_clone(&clone, client);
+       if (clone == NULL) {
+               g_print("tetheirng_client_clone is failed\n");
+               return;
+       }
+
+       softap_client_get_ip_address(clone,
+                       SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
+       softap_client_get_mac_address(clone, &mac_address);
+       softap_client_get_name(clone, &hostname);
+
+       if (open) {
+               g_print("## New station IP [%s], MAC [%s], hostname [%s]\n",
+                               ip_address, mac_address, hostname);
+       } else {
+               g_print("## Disconnected station IP [%s], MAC [%s], hostname [%s]\n",
+                               ip_address, mac_address, hostname);
+       }
+
+       if (ip_address)
+               free(ip_address);
+       if (mac_address)
+               free(mac_address);
+       if (hostname)
+               free(hostname);
+
+       softap_client_destroy(clone);
+
+       return;
+}
+
+static void __register_cbs(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+
+       ret = softap_set_enabled_cb(sa, __enabled_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set enabled callback!!\n");
+
+       ret = softap_set_disabled_cb(sa, __disabled_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set disabled callback!!\n");
+
+       ret = softap_set_security_type_changed_cb(sa, __security_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set security changed callback!!\n");
+
+       ret = softap_set_ssid_visibility_changed_cb(sa, __ssid_visibility_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set visibility changed callback!!\n");
+
+       ret = softap_set_passphrase_changed_cb(sa, __passphrase_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set passphrase changed callback!!\n");
+
+       ret = softap_set_client_connection_state_changed_cb(sa, __connection_state_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set client connection state changed callback!!\n");
+
+       return;
+}
+
+static void __deregister_cbs(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+
+       ret = softap_unset_enabled_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset enabled callback!!\n");
+
+       ret = softap_unset_disabled_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset disabled callback!!\n");
+
+       ret = softap_unset_security_type_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset security changed callback!!\n");
+
+       ret = softap_unset_ssid_visibility_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset visibility changed callback!!\n");
+
+       ret = softap_unset_client_connection_state_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset client connection state changed callback!!\n");
+
+       return;
+}
+
+
+static int test_softap_create(void)
+{
+       softap_create(&sa);
+       __register_cbs();
+
+       return 1;
+}
+
+static int test_softap_destroy(void)
+{
+       __deregister_cbs();
+       softap_destroy(sa);
+       sa = NULL;
+
+       return 1;
+}
+
+static int test_softap_enable(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+
+       ret = softap_enable(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_disable(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+
+       ret = softap_disable(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_is_enabled(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+       bool enabled = false;
+
+       ret = softap_is_enabled(sa, &enabled);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       printf("Soft AP is %s\n", enabled ? "enabled" : "disabled");
+
+       return 1;
+}
+
+static int test_softap_get_settings(void)
+{
+       int ret = SOFTAP_ERROR_NONE;
+       char *ssid = NULL;
+       char *passphrase = NULL;
+       char *mac_address = NULL;
+       char *interface_name = NULL;
+       char *ip_address = NULL;
+       char *gateway_address = NULL;
+       char *subnet_mask = NULL;
+       char *vendor = NULL;
+       bool visible = false;
+       bool dhcp_enabled = false;
+       softap_security_type_e security_type = SOFTAP_SECURITY_TYPE_NONE;
+       softap_wireless_mode_e mode = SOFTAP_WIRELESS_MODE_G;
+       int channel;
+
+       ret = softap_get_ssid(sa, &ssid);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get ssid\n");
+
+       ret = softap_get_passphrase(sa, &passphrase);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get passphrase\n");
+
+       ret = softap_get_ssid_visibility(sa, &visible);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get ssid visibility\n");
+
+       ret = softap_get_security_type(sa, &security_type);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get security type\n");
+
+       ret = softap_get_channel(sa, &channel);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get channel\n");
+
+       ret = softap_get_mode(sa, &mode);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get mode\n");
+
+       ret = softap_get_mac_address(sa, &mac_address);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get mac address\n");
+
+       ret = softap_get_network_interface_name(sa, &interface_name);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get interface name\n");
+
+       ret = softap_get_ip_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get IP address\n");
+
+       ret = softap_get_gateway_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway_address);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get gateway address\n");
+
+       ret = softap_get_subnet_mask(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &subnet_mask);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get subnet mask\n");
+
+       ret = softap_get_vendor_element(sa, &vendor);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get vendor element\n");
+
+       ret = softap_is_dhcp_enabled(sa, &dhcp_enabled);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get dhcp state\n");
+
+       printf("* SSID: %s\n", ssid);
+       printf("* SSID visibility: %d\n", visible);
+       printf("* Security type: %d\n", security_type);
+       printf("* Passphrase: %s\n", passphrase);
+       printf("* Channel: %d\n", channel);
+       printf("* Mode: %d\n", mode);
+       printf("* MAC address: %s\n", mac_address);
+       printf("* Network Interface: %s\n", interface_name);
+       printf("* IP address: %s\n", ip_address);
+       printf("* Gateway address: %s\n", gateway_address);
+       printf("* Subnetmask: %s\n", subnet_mask);
+       printf("* Vendor element: %s\n", vendor);
+       printf("* DHCP: %s\n", (dhcp_enabled ? "enabled" : "disabled"));
+
+       if (ssid) g_free(ssid);
+       if (passphrase) g_free(passphrase);
+       if (mac_address) g_free(mac_address);
+       if (interface_name)     g_free(interface_name);
+       if (ip_address) g_free(ip_address);
+       if (gateway_address) g_free(gateway_address);
+       if (subnet_mask) g_free(subnet_mask);
+       if (vendor) g_free(vendor);
+
+       return 1;
+}
+
+static int test_softap_set_ssid(void)
+{
+       int ret;
+       char ssid[100];
+
+       printf("Input SSID for Softap: ");
+       ret = scanf("%99s", ssid);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_ssid(sa, ssid);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_ssid_visibility(void)
+{
+       int ret;
+       int visibility;
+
+       printf("Input visibility for Soft AP (0:invisible, 1:visible)");
+       ret = scanf("%9d", &visibility);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_ssid_visibility(sa, visibility);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_security_type(void)
+{
+       int ret;
+       int security_type;
+
+       printf("Input security type for Soft AP (0:NONE, 1:WPA2_PSK, 2:WPS)");
+       ret = scanf("%9d", &security_type);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return -1;
+       }
+
+       ret = softap_set_security_type(sa, security_type);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_passphrase(void)
+{
+       int ret;
+       char passphrase[65];
+
+       printf("Input passphrase for Softap: ");
+       ret = scanf("%64s", passphrase);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_passphrase(sa, passphrase);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_vendor_element(void)
+{
+       int ret;
+       char vendor[1024];
+
+       printf("Input vendor elements(e.g. DD050016328000, DD050016321000): ");
+       ret = scanf("%1023s", vendor);
+
+       ret = softap_set_vendor_element(sa, vendor);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_channel(void)
+{
+       int ret;
+       int channel;
+
+       printf("Input channel for Soft AP: ");
+       ret = scanf("%9d", &channel);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return -1;
+       }
+
+       ret = softap_set_channel(sa, channel);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_reload_settings(void)
+{
+       int ret = softap_reload_settings(sa, __settings_reloaded_cb, NULL);
+
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_get_client_info(void)
+{
+       int ret;
+
+       ret = softap_foreach_connected_clients(sa, __clients_foreach_cb, NULL);
+
+       if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+
+       return 1;
+}
+
+static int test_softap_push_wps_button(void)
+{
+       int ret;
+
+       ret = softap_push_wps_button(sa);
+
+       if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+
+       return 1;
+}
+
+static int test_softap_set_wps_pin(void)
+{
+       int ret;
+       char wps_pin[128];
+
+       printf("Input WPS PIN: ");
+       ret = scanf("%127s", wps_pin);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+       ret = softap_set_wps_pin(sa, wps_pin);
+
+       if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+
+       return 1;
+}
+
+static int test_softap_enable_dhcp(void)
+{
+       int ret;
+       int enable_type;
+       char rangestart[16];
+       char rangestop[16];
+
+       printf("Enable with range? (0. no, 1. yes): ");
+       ret = scanf("%d", &enable_type);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       if (enable_type) {
+               printf("Input DHCP range\n");
+               printf("Start: ");
+               ret = scanf("%15s", rangestart);
+               if (ret < 0) {
+                       printf("scanf is failed!!\n");
+                       return 0;
+               }
+
+               printf("Stop: ");
+               ret = scanf("%15s", rangestop);
+               if (ret < 0) {
+                       printf("scanf is failed!!\n");
+                       return 0;
+               }
+
+               ret = softap_enable_dhcp_with_range(sa, rangestart, rangestop);
+               if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+       } else {
+               ret = softap_enable_dhcp(sa);
+               if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+       }
+
+       return 1;
+}
+
+static int test_softap_disable_dhcp(void)
+{
+       int ret;
+
+       ret = softap_disable_dhcp(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_mode(void)
+{
+       int ret;
+       int type;
+
+       printf("Input wireless for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
+       ret = scanf("%d", &type);
+
+       ret = softap_set_mode(sa, type);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_ip_address(void)
+{
+       int ret;
+       char ip[16];
+
+       printf("Input IP address for Softap(IPv4 only): ");
+       ret = scanf("%15s", ip);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_ip_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, ip);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+int main(int argc, char **argv)
+{
+       GMainLoop *mainloop;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+       g_type_init();
+#endif
+       mainloop = g_main_loop_new(NULL, false);
+
+       GIOChannel *channel = g_io_channel_unix_new(0);
+       g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
+       printf("Test Thread created...\n");
+       g_main_loop_run(mainloop);
+
+       return 0;
+}
+
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+       int rv;
+       char a[10];
+
+       printf("Event received from stdin\n");
+
+       rv = read(0, a, 10);
+
+       if (rv <= 0 || a[0] == '0')
+               exit(1);
+
+       if (a[0] == '\n' || a[0] == '\r') {
+               printf("\n\n Network Connection API Test App\n\n");
+               printf("Options..\n");
+               printf("1       - SoftAP create and set callbacks\n");
+               printf("2       - SoftAP destroy\n");
+               printf("3       - SoftAP enable\n");
+               printf("4       - SoftAP disable\n");
+               printf("5       - Is Soft AP enabled?\n");
+               printf("6       - Get Soft AP settings\n");
+               printf("7       - Set Soft AP SSID\n");
+               printf("8       - Set Soft AP SSID visibility\n");
+               printf("9       - Set Soft AP security type\n");
+               printf("a       - Set Soft AP passpharse\n");
+               printf("b       - Set Soft AP vendor element\n");
+               printf("c       - Set Soft AP channel\n");
+               printf("d       - Get Soft AP client information\n");
+               printf("e       - SoftAP reload settings\n");
+               printf("f       - Push WPS Button (WPS PBC)\n");
+               printf("g       - Set WPS PIN\n");
+               printf("h       - Enable DHCP Server\n");
+               printf("i       - Disable DHCP Server\n");
+               printf("j       - Set wireless mode\n");
+               printf("k       - Set IP address (IPv4 only)\n");
+               printf("0       - Exit \n");
+               printf("ENTER  - Show options menu.......\n");
+       }
+
+       switch (a[0]) {
+       case '1':
+               rv = test_softap_create();
+               break;
+       case '2':
+               rv = test_softap_destroy();
+               break;
+       case '3':
+               rv = test_softap_enable();
+               break;
+       case '4':
+               rv = test_softap_disable();
+               break;
+       case '5':
+               rv = test_softap_is_enabled();
+               break;
+       case '6':
+               rv = test_softap_get_settings();
+               break;
+       case '7':
+               rv = test_softap_set_ssid();
+               break;
+       case '8':
+               rv = test_softap_set_ssid_visibility();
+               break;
+       case '9':
+               rv = test_softap_set_security_type();
+               break;
+       case 'a':
+               rv = test_softap_set_passphrase();
+               break;
+       case 'b':
+               rv = test_softap_set_vendor_element();
+               break;
+       case 'c':
+               rv = test_softap_set_channel();
+               break;
+       case 'd':
+               rv = test_softap_get_client_info();
+               break;
+       case 'e':
+               rv = test_softap_reload_settings();
+               break;
+       case 'f':
+               rv = test_softap_push_wps_button();
+               break;
+       case 'g':
+               rv = test_softap_set_wps_pin();
+               break;
+       case 'h':
+               rv = test_softap_enable_dhcp();
+               break;
+       case 'i':
+               rv = test_softap_disable_dhcp();
+               break;
+       case 'j':
+               rv = test_softap_set_mode();
+               break;
+       case 'k':
+               rv = test_softap_set_ip_address();
+               break;
+       }
+
+       if (rv == 1)
+               printf("Operation succeeded!\n");
+       else
+               printf("Operation failed!\n");
+
+       return true;
+}