ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(pkgconfig)
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tests/nan-test)
+ADD_SUBDIRECTORY(tests/unittest)
ADD_SUBDIRECTORY(cts-verifier)
* @return 0 on success, otherwise a negative error value
* @retval #WIFI_AWARE_ERROR_NONE
* @retval #WIFI_AWARE_ERROR_ALREADY_INITIALIZED
+ * @retval #WIFI_AWARE_ERROR_OPERATION_FAILED
* @see wifi_aware_deinitialize()
*/
int wifi_aware_initialize();
Group: Network & Connectivity/API
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(gobject-2.0)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(gmock)
+%if 0%{?gcov:1}
+BuildRequires: lcov
+%endif
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description cts-verifier
cts-verifier command app
+%if 0%{?gcov:1}
+%package gcov
+Summary: Coverage Data of %{name}
+
+%description gcov
+The %{name}-gcov package contains gcov objects
+%endif
%prep
%setup -q
chmod 644 %{SOURCE0}
+cp %{SOURCE1} ./%{name}.manifest
%ifarch %{arm}
export ARCH=arm
%endif
%build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
+
%if 0%{?sec_build_binary_debug_enable}
export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
-DMAJORVER=${MAJORVER}
make %{?jobs:-j%jobs}
+%if 0%{?gcov:1}
+mkdir -p gcov-obj
+find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
+%endif
+
%install
rm -rf %{buildroot}
%make_install
+%if 0%{?gcov:1}
+mkdir -p %{buildroot}%{_datadir}/gcov/obj
+install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+%endif
+
+%check
+export LD_LIBRARY_PATH=./src/
+LD_PRELOAD=./tests/unittest/libwifi-aware-mock.so ./tests/unittest/wifi-aware-unittest
+#LD_LIBRARY_PATH=
+
+%if 0%{?gcov:1}
+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
%postun -p /sbin/ldconfig
%files
-%manifest capi-network-wifi-aware.manifest
+%manifest %{name}.manifest
%license LICENSE
%defattr(-,root,root,-)
%{_libdir}/*.so.*
%{_libdir}/*.so
%files test
-%manifest wifi-aware-test.manifest
+%manifest %{name}.manifest
%attr(755,root,root) %{_bindir}/wifi-aware-test
%attr(755,root,root) %{_bindir}/wifi-aware-publish-test
%attr(755,root,root) %{_bindir}/wifi-aware-subscribe-test
%files cts-verifier
#%manifest wifi-aware-test.manifest
%attr(755,root,root) %{_bindir}/cts-verifier
+
+%if 0%{?gcov:1}
+%files gcov
+%{_datadir}/gcov/obj/*
+%endif
&& security_type <= WIFI_AWARE_SECURITY_TYPE_PMK;
}
-//LCOV_EXCL_START
static uint32_t __data_path_get_ndp_id(wifi_aware_data_path_h data_path)
{
wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path;
wifi_aware_gdbus_deregister_signal(DATA_PATH_TERMINATED_SIGNAL);
ndp->terminated_signal_id = 0;
-
+
__WIFI_AWARE_FUNC_ENTER__;
return ret;
}
-//LCOV_EXCL_STOP
if (gdbus_data.connection != NULL) {
WIFI_AWARE_LOGI("There's already gdbus connection"); //LCOV_EXCL_LINE
__WIFI_AWARE_FUNC_EXIT__; //LCOV_EXCL_LINE
- return 0;
+ return WIFI_AWARE_ERROR_NONE;
}
gdbus_data.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (gdbus_data.connection == NULL) {
WIFI_AWARE_LOGI("Failed to get connection, Error[%s]\n", error->message); //LCOV_EXCL_LINE
g_error_free(error); //LCOV_EXCL_LINE
- return -1;
+ return WIFI_AWARE_ERROR_OPERATION_FAILED;
}
gdbus_data.cancellable = g_cancellable_new();
return ret;
}
-//LCOV_EXCL_START
int wifi_aware_gdbus_followup(wifi_aware_session_h session,
int client_id, uint16_t pub_sub_id, unsigned int peer_id,
const unsigned char *message, size_t len,
__WIFI_AWARE_FUNC_EXIT__;
return ret;
}
-//LCOV_EXCL_STOP
+
unsigned char mac[WIFI_AWARE_MAC_ADDRESS_LEN];
} wifi_aware_peer_s;
-//LCOV_EXCL_START
int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id)
{
wifi_aware_peer_s *peer_handle = (wifi_aware_peer_s *)g_try_malloc0(sizeof(wifi_aware_peer_s));
wifi_aware_peer_s *handle = (wifi_aware_peer_s *)peer;
memcpy(handle->mac, mac, WIFI_AWARE_MAC_ADDRESS_LEN);
}
-//LCOV_EXCL_STOP
}
}
-//LCOV_EXCL_START
static void __wifi_aware_discovered_cb(wifi_aware_session_h session, wifi_aware_peer_h peer,
const unsigned char *specific_info, size_t specific_info_len, int distance)
{
if (handle->terminated_cb)
handle->terminated_cb(session, reason, handle->terminated_cb_data);
}
-//LCOV_EXCL_STOP
static wifi_aware_error_e __get_dbus_result(GObject *src, GAsyncResult *res, uint16_t *id)
{
g_variant_get(parameters, "(qi)", pub_sub_id, reason);
}
-//LCOV_EXCL_START
static void __session_terminated_cb(GDBusConnection *connection,
const gchar *sender, const gchar *object_path,
const gchar *interface, const gchar *signal,
__session_set_pub_sub_id(session, 0);
__wifi_aware_session_terminated_cb(session, (wifi_aware_termination_reason_e)reason);
}
-//LCOV_EXCL_STOP
void _wifi_aware_session_set_terminated_cb(wifi_aware_session_h session,
wifi_aware_session_terminated_cb callback, void *user_data)
return true;
}
-//LCOV_EXCL_START
static bool __parsing_service_discovered_event(GVariant *parameters,
uint16_t *sub_id, unsigned int *peer_id, unsigned char *peer_mac,
unsigned char *specific_info, size_t *specific_info_len, int *distance)
_wifi_aware_peer_set_mac(peer, peer_mac);
__wifi_aware_received_cb(session, peer, message, message_len);
}
-//LCOV_EXCL_STOP
int _wifi_aware_set_service_discovered_cb(wifi_aware_session_h session,
wifi_aware_service_discovered_cb callback, void *user_data)
g_free(message);
}
-//LCOV_EXCL_START
static void __wifi_aware_followup_invoke_callback(wifi_aware_message_s *message, wifi_aware_error_e error)
{
if (message && message->callback) {
__send_message_reply,
message_data);
}
-//LCOV_EXCL_STOP
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-SET(WIFI_AWARE_TEST_INCLUDE_DIR ${WIFI_AWARE_TEST_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+SET(WIFI_AWARE_TEST_INCLUDE_DIR ${WIFI_AWARE_TEST_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${WIFI_AWARE_TEST_INCLUDE_DIR})
INCLUDE(FindPkgConfig)
static void __print_test_result(int num, bool result)
{
- char test_name[20] = {0, };
+ char test_name[30] = {0, };
if (num < NEGATIVE_TEST_01)
- snprintf(test_name, 19, "%s %d", "Positivie Test", num);
+ snprintf(test_name, 29, "%s %d", "Positive Test", num);
else
- snprintf(test_name, 19, "%s %d", "Negative Test", num - NEGATIVE_TEST_01 + 1);
+ snprintf(test_name, 29, "%s %d", "Negative Test", num - NEGATIVE_TEST_01 + 1);
if (result)
printf(MAKE_GREEN"[%s] is pass."RESET_COLOR"\n", test_name);
static void __print_test_result(int num, bool result)
{
- char test_name[20] = {0, };
+ char test_name[30] = {0, };
if (num < NEGATIVE_TEST_01)
- snprintf(test_name, 19, "%s %d", "Positivie Test", num);
+ snprintf(test_name, 29, "%s %d", "Positivie Test", num);
else
- snprintf(test_name, 19, "%s %d", "Negative Test", num - NEGATIVE_TEST_01 + 1);
+ snprintf(test_name, 29, "%s %d", "Negative Test", num - NEGATIVE_TEST_01 + 1);
if (result)
printf(MAKE_GREEN"[%s] is pass."RESET_COLOR"\n", test_name);
--- /dev/null
+# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# @file CMakeLists.txt
+#
+
+SET(WIFI_AWARE_MOCK "wifi-aware-mock")
+SET(WIFI_AWARE_MOCK_SRCS
+ mocks/wifi-aware-mock.c
+ mocks/wifi-aware-mock-gdbus-internal.c)
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/src/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/mocks
+ )
+ADD_DEFINITIONS("-fvisibility=default")
+ADD_LIBRARY(${WIFI_AWARE_MOCK} SHARED ${WIFI_AWARE_MOCK_SRCS})
+
+
+SET(WIFI_AWARE_UNITTEST "wifi-aware-unittest")
+
+pkg_check_modules(TARGET_WIFI_AWARE_UNITTEST REQUIRED
+ capi-system-info
+ glib-2.0
+ gmock
+)
+INCLUDE_DIRECTORIES(
+ ${TARGET_WIFI_AWARE_UNITTEST_INCLUDE_DIRS}
+)
+LINK_DIRECTORIES(${TARGET_WIFI_AWARE_UNITTEST_LIBRARY_DIRS})
+
+FILE(GLOB UNITTEST_SRCS *.cpp)
+
+ADD_EXECUTABLE(${WIFI_AWARE_UNITTEST} ${UNITTEST_SRCS})
+TARGET_LINK_LIBRARIES(${WIFI_AWARE_UNITTEST}
+ ${TARGET_WIFI_AWARE}
+ ${TARGET_WIFI_AWARE_UNITTEST_LIBRARIES}
+)
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <glib.h>
+#include "wifi-aware-mock-gdbus-internal.h"
+
+typedef struct {
+ GAsyncReadyCallback callback;
+ GVariant *result;
+ gpointer user_data;
+} gdbus_result_data_s;
+
+static gdbus_result_data_s _gdbus_async_result;
+
+static gboolean __reply_async_method(gpointer data)
+{
+ gdbus_result_data_s *gdbus_result = (gdbus_result_data_s *)data;
+ gdbus_result->callback((GObject *)_get_dummy_gdbus_connection(),
+ NULL,
+ gdbus_result->user_data);
+ return FALSE;
+}
+
+static void __enable_handler(GVariant *parameters, GAsyncReadyCallback callback, gpointer user_data)
+{
+ // Always Success
+ _gdbus_async_result.callback = callback;
+ _gdbus_async_result.result = g_variant_new("(ii)", DUMMY_CLIENT_ID, WIFI_AWARE_ERROR_NONE);
+ _gdbus_async_result.user_data = user_data;
+ g_timeout_add(ASYNC_RESULT_DELAY, __reply_async_method, &_gdbus_async_result);
+}
+
+static GVariant *__disable_handler(GVariant *parameters)
+{
+ GVariant *reply = g_variant_new("(i)", WIFI_AWARE_ERROR_NONE);
+ return reply;
+}
+
+struct {
+ const gchar *interface_name;
+ const gchar *method_name;
+ // parameters is omitted
+ void(*async_handler)(GVariant *parameters, GAsyncReadyCallback callback, gpointer user_data);
+ GVariant *(*sync_handler)(GVariant *parameters);
+} wifi_aware_g_dbus_method_list[] = {
+ {
+ "net.nan.discovery",
+ "Enable",
+ __enable_handler,
+ NULL,
+ },
+ {
+ "net.nan.discovery",
+ "Disable",
+ NULL,
+ __disable_handler,
+ },
+ /*
+ {
+ "net.nan.discovery",
+ "Publish",
+ },
+ {
+ "net.nan.discovery",
+ "UpdatePublish",
+ },
+ {
+ "net.nan.discovery",
+ "CancelPublish",
+ },
+ */
+ {
+ NULL,
+ NULL,
+ NULL,
+ },
+};
+
+GDBusConnection *_get_dummy_gdbus_connection()
+{
+ return (GDBusConnection *)g_object_new(G_TYPE_DBUS_CONNECTION, NULL);
+}
+
+bool _check_g_dbus_bus_name(const gchar *bus_name)
+{
+ return g_strcmp0(bus_name, WIFI_AWARE_INTERFACE) == 0;
+}
+
+bool _check_g_dbus_object_path(const gchar *object_path)
+{
+ return g_strcmp0(object_path, WIFI_AWARE_DISCOVERY_PATH) == 0;
+}
+
+bool _check_g_dbus_interface_name(const gchar *interface_name)
+{
+ return g_strcmp0(interface_name, WIFI_AWARE_DISCOVERY_INTERFACE) == 0;
+}
+
+static bool __is_same_method(int i, const char *interface_name, const char *method_name)
+{
+ return (g_strcmp0(wifi_aware_g_dbus_method_list[i].interface_name, interface_name) == 0
+ && g_strcmp0(wifi_aware_g_dbus_method_list[i].method_name, method_name) == 0);
+}
+
+void _handle_async_method(const gchar *interface_name,
+ const char *method_name, GVariant *parameters,
+ GAsyncReadyCallback callback, gpointer user_data)
+{
+ for (int i = 0; ; ++i) {
+ if (wifi_aware_g_dbus_method_list[i].interface_name == NULL)
+ return;
+ if (__is_same_method(i, interface_name, method_name))
+ wifi_aware_g_dbus_method_list[i].async_handler(parameters, callback, user_data);
+ }
+}
+
+GVariant *_get_gdbus_async_result(GError **error)
+{
+ *error = NULL;
+ return _gdbus_async_result.result;
+}
+
+void _set_gdbus_error(gint code, const char *message, GError **error)
+{
+ *error = g_error_new_literal(G_DBUS_ERROR, code, message);
+}
+
+GVariant *_handle_sync_method(const gchar *interface_name,
+ const char *method_name, GVariant *parameters, GError **error)
+{
+ for (int i = 0; ; ++i) {
+ if (wifi_aware_g_dbus_method_list[i].interface_name == NULL) {
+ _set_gdbus_error(G_DBUS_ERROR_UNKNOWN_METHOD, "UnknownMethod", error);
+ return NULL;
+ }
+ if (__is_same_method(i, interface_name, method_name))
+ return wifi_aware_g_dbus_method_list[i].sync_handler(parameters);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "wifi-aware-gdbus.h"
+
+#define ASYNC_RESULT_DELAY 500
+#define DUMMY_CLIENT_ID 1
+
+GDBusConnection *_get_dummy_gdbus_connection();
+bool _check_g_dbus_bus_name(const gchar *bus_name);
+bool _check_g_dbus_object_path(const gchar *object_path);
+bool _check_g_dbus_interface_name(const gchar *interface_name);
+void _handle_async_method(const gchar *interface_name,
+ const char *method_name, GVariant *parameters,
+ GAsyncReadyCallback callback, gpointer user_data);
+GVariant *_get_gdbus_async_result(GError **error);
+void _set_gdbus_error(gint code, const char *message, GError **error);
+GVariant *_handle_sync_method(const gchar *interface_name,
+ const char *method_name, GVariant *parameters, GError **error);
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <system_info.h>
+
+#include "wifi-aware-mock-gdbus-internal.h"
+
+int system_info_get_platform_bool(const char *key, bool *value)
+{
+ *value = true;
+ return SYSTEM_INFO_ERROR_NONE;
+}
+
+bool _wifi_aware_check_permission()
+{
+ return true;
+}
+
+GDBusConnection *g_bus_get_sync(GBusType bus_type, GCancellable *cancellable, GError **error)
+{
+ return _get_dummy_gdbus_connection();
+}
+
+GCancellable *g_cancellable_new()
+{
+ return (GCancellable *)g_object_new(G_TYPE_CANCELLABLE, NULL);
+}
+
+void
+g_dbus_connection_call(GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ const GVariantType *reply_type,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ if (!_check_g_dbus_bus_name(bus_name))
+ return;
+ if (!_check_g_dbus_object_path(object_path))
+ return;
+ if (!_check_g_dbus_interface_name(interface_name))
+ return;
+ _handle_async_method(interface_name, method_name, parameters, callback, user_data);
+}
+
+GVariant *g_dbus_connection_call_finish(GDBusConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ return _get_gdbus_async_result(error);
+}
+
+GVariant *g_dbus_connection_call_sync(GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ const GVariantType *reply_type,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GError **error)
+{
+ if (!_check_g_dbus_bus_name(bus_name)) {
+ _set_gdbus_error(G_DBUS_ERROR_UNKNOWN_METHOD, "UnknownMethod", error);
+ return NULL;
+ }
+ if (!_check_g_dbus_object_path(object_path)) {
+ _set_gdbus_error(G_DBUS_ERROR_UNKNOWN_METHOD, "UnknownMethod", error);
+ return NULL;
+ }
+ if (!_check_g_dbus_interface_name(interface_name)) {
+ _set_gdbus_error(G_DBUS_ERROR_UNKNOWN_METHOD, "UnknownMethod", error);
+ return NULL;
+ }
+ return _handle_sync_method(interface_name, method_name, parameters, error);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <gtest/gtest.h>
+#include <system_info.h>
+
+#include "wifi-aware.h"
+
+#define WIFI_AWARE_FEATURE "http://tizen.org/feature/network.wifi.aware"
+
+bool g_enabled;
+bool g_wifi_aware_supported;
+
+class WifiAware : public ::testing::Test
+{
+protected:
+ virtual void SetUp() {
+ g_enabled = false;
+ g_wifi_aware_supported = false;
+ system_info_get_platform_bool(WIFI_AWARE_FEATURE, &g_wifi_aware_supported);
+ wifi_aware_initialize();
+ }
+
+ virtual void TearDown() {
+ wifi_aware_deinitialize();
+ }
+
+};
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-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 "wifi-aware-unittest-util.h"
+
+GMainLoop *g_main_loop;
+guint g_timeout_id;
+
+gboolean _wifi_aware_callback_timeout(gpointer data)
+{
+ GMainLoop *main_loop = NULL;
+ main_loop = (GMainLoop *)data;
+ if (main_loop != NULL)
+ {
+ g_main_loop_quit(main_loop);
+ }
+ return false;
+}
+
+const char *_convert_error_to_string(wifi_aware_error_e error)
+{
+ switch (error) {
+ case WIFI_AWARE_ERROR_NONE:
+ return "NO ERROR";
+ case WIFI_AWARE_ERROR_NOT_PERMITTED:
+ return "NOT_PERMITTED";
+ case WIFI_AWARE_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+ case WIFI_AWARE_ERROR_PERMISSION_DENIED:
+ return "PERMISSION_DENIED";
+ case WIFI_AWARE_ERROR_RESOURCE_BUSY:
+ return "RESOURCE_BUSY";
+ case WIFI_AWARE_ERROR_INVALID_PARAMETER:
+ return "INVALID_PARAMETER";
+ case WIFI_AWARE_ERROR_NOW_IN_PROGRESS:
+ return "NOW_IN_PROGRESS";
+ case WIFI_AWARE_ERROR_NOT_SUPPORTED:
+ return "NOT_SUPPORTED";
+ case WIFI_AWARE_ERROR_OPERATION_FAILED:
+ return "OPERATION_FAILED";
+ case WIFI_AWARE_ERROR_NOT_INITIALIZED:
+ return "NOT_INITIALIZED";
+ case WIFI_AWARE_ERROR_ALREADY_INITIALIZED:
+ return "ALREADY_INITIALIZED";
+ case WIFI_AWARE_ERROR_ALREADY_ENABLED:
+ return "ALREADY_ENABLED";
+ case WIFI_AWARE_ERROR_REJECTED_BY_PEER:
+ return "REJECTED_BY_PEER";
+ case WIFI_AWARE_ERROR_INTERFACE_DOWN:
+ return "INTERFACE_IS_DOWN";
+ default:
+ return "UNKNOWN";
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-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 <glib.h>
+#include "wifi-aware.h"
+
+#define CHECK_WIFI_AWARE_SUPPORTED(ret) do { \
+ if (!g_wifi_aware_supported) { \
+ ASSERT_EQ(ret, WIFI_AWARE_ERROR_NOT_SUPPORTED) \
+ << "FAIL NOT_SUPPORTED"; \
+ } \
+ } while (0)
+
+#define CHECK_RESULT(ret, expected, message) do { \
+ CHECK_WIFI_AWARE_SUPPORTED(ret); \
+ ASSERT_EQ(ret, expected) << "FAIL " << message; \
+ } while (0)
+
+#define CALLBACK_TIMEOUT 20000
+#define RUN_GMAIN_LOOP do { \
+ g_main_loop = g_main_loop_new(NULL, false); \
+ g_timeout_id = g_timeout_add(CALLBACK_TIMEOUT, _wifi_aware_callback_timeout, g_main_loop); \
+ g_main_loop_run(g_main_loop); \
+ g_source_remove(g_timeout_id); \
+ g_main_loop = NULL; \
+ } while (0)
+
+#define QUIT_GMAIN_LOOP do { \
+ if (g_main_loop) { \
+ g_main_loop_quit(g_main_loop); \
+ g_main_loop = NULL; \
+ } \
+ } while (0)
+
+gboolean _wifi_aware_callback_timeout(gpointer data);
+const char *_convert_error_to_string(wifi_aware_error_e error);
--- /dev/null
+/*
+ * Copyright (c) 2019-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 <iostream>
+#include <gtest/gtest.h>
+
+#include "wifi-aware-unittest-fixture.h"
+#include "wifi-aware-unittest-util.h"
+#include "wifi-aware.h"
+
+extern GMainLoop *g_main_loop;
+extern guint g_timeout_id;
+
+void __enabled_cb(wifi_aware_error_e error, void *user_data)
+{
+ if (error == WIFI_AWARE_ERROR_NONE) {
+ // LOGI("Successfully Enabled");
+ g_enabled = true;
+ }
+ else {
+ // LOGE("Fail to enable %s(%d)", _wifi_aware_error_to_string(error), error);
+ }
+ QUIT_GMAIN_LOOP;
+}
+
+TEST_F(WifiAware, wifi_aware_initialize_p)
+{
+ int ret = 0;
+
+ wifi_aware_deinitialize();
+
+ ret = wifi_aware_initialize();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_NONE, "wifi_aware_initialize");
+}
+
+TEST_F(WifiAware, wifi_aware_initialize_n)
+{
+ int ret = 0;
+ ret = wifi_aware_initialize();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_ALREADY_INITIALIZED, "wifi_aware_initialize");
+}
+
+TEST_F(WifiAware, wifi_aware_deinitialize_p)
+{
+ int ret = 0;
+ ret = wifi_aware_deinitialize();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_NONE, "wifi_aware_deinitialize");
+}
+
+TEST_F(WifiAware, wifi_aware_deinitialize_n)
+{
+ int ret = 0;
+ wifi_aware_deinitialize();
+
+ ret = wifi_aware_deinitialize();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_NOT_INITIALIZED, "wifi_aware_deinitialize");
+}
+
+TEST_F(WifiAware, wifi_aware_enable_p)
+{
+ int ret = 0;
+
+ ret = wifi_aware_enable(__enabled_cb, NULL);
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_NONE, "wifi_aware_enable");
+
+ RUN_GMAIN_LOOP;
+
+ ASSERT_TRUE(g_enabled) << "FAIL Enabled";
+
+ wifi_aware_disable();
+}
+
+TEST_F(WifiAware, wifi_aware_enable_n)
+{
+ int ret = 0;
+
+ wifi_aware_enable(__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ ret = wifi_aware_enable(__enabled_cb, NULL);
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_ALREADY_ENABLED, "wifi_aware_enable");
+
+ wifi_aware_disable();
+}
+
+TEST_F(WifiAware, wifi_aware_disable_p)
+{
+ int ret = 0;
+
+ wifi_aware_enable(__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ ret = wifi_aware_disable();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_NONE, "wifi_aware_disable");
+
+ wifi_aware_disable();
+}
+
+TEST_F(WifiAware, wifi_aware_disable_n)
+{
+ int ret = 0;
+
+ ret = wifi_aware_disable();
+ CHECK_RESULT(ret, WIFI_AWARE_ERROR_INVALID_OPERATION, "wifi_aware_disable");
+}