SET(LIB_DEPS "dlog glib-2.0 gio-2.0 capi-base-common capi-system-info gio-unix-2.0 gssdp-1.0 dns_sd cynara-client")
SET(PC_DEPS "capi-base-common")
SET(TEST_DEPS "glib-2.0")
-SET(GTEST_DEPS "gmock capi-system-info cynara-client")
+SET(GTEST_DEPS "gmock" ${LIB_DEPS})
SET(TARGET_NSD "nsd")
SET(TARGET_LIB_NSD_DNS_SD "nsd-dns-sd")
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(pkgconfig)
-ADD_SUBDIRECTORY(tests)
\ No newline at end of file
+ADD_SUBDIRECTORY(tests)
%endif
%check
-LD_LIBRARY_PATH=./src/ssdp:./src/dns-sd tests/tct-nsd-core
+tests/tct-nsd-core
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -b . -d . -o nsd.info
genhtml nsd.info -o out --legend --show-details
return __dnssd_process_result(condition, reply->sd_ref);
}
-static guint __dnssd_io_add_watch(int fd, GIOFunc func, gpointer data)
+guint __dnssd_io_add_watch(GIOChannel *channel,
+ GIOFunc func, gpointer data)
+{
+ guint watch_id;
+ GMainContext *context = NULL;
+ GSource *source = g_io_create_watch(channel,
+ (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL));
+
+ g_source_set_callback(source, (GSourceFunc)func, data, NULL);
+ context = g_main_context_get_thread_default();
+
+ watch_id = g_source_attach(source, context);
+ g_source_unref(source);
+
+ return watch_id;
+}
+
+static guint __dnssd_watch_fd(int fd, GIOFunc func, gpointer data)
{
guint watch_id;
GIOChannel *sock_io = NULL;
sock_io = g_io_channel_unix_new(fd);
g_io_channel_set_flags(sock_io, G_IO_FLAG_NONBLOCK, NULL);
g_io_channel_set_close_on_unref(sock_io, FALSE);
- watch_id = g_io_add_watch(sock_io, (G_IO_IN | G_IO_HUP |
- G_IO_ERR | G_IO_NVAL), func, data);
- DNSSD_LOGD("watch_id %u", watch_id);
+ watch_id = __dnssd_io_add_watch(sock_io, func, data);
g_io_channel_unref(sock_io);
return watch_id;
}
return;
}
- *watch_id = __dnssd_io_add_watch(dns_sd_fd, __dnssd_handle_io_events, handle);
+ *watch_id = __dnssd_watch_fd(dns_sd_fd, __dnssd_handle_io_events, handle);
}
static void __dnssd_resolve_data_add_event_handler(guint *watch_id, resolve_reply_data *data)
return;
}
- *watch_id = __dnssd_io_add_watch(dns_sd_fd, __dnssd_resolve_data_io_events, data);
+ *watch_id = __dnssd_watch_fd(dns_sd_fd, __dnssd_resolve_data_io_events, data);
}
EXPORT_API int dnssd_initialize(void)
LINK_DIRECTORIES(${unittest_pkgs_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(
- ${CMAKE_SOURCE_DIR}/include
- ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${unittest_pkgs_INCLUDE_DIRS}
)
FILE(GLOB NSD_MOCK_SRCS mock/*.c)
)
# Build
-ADD_EXECUTABLE(${UNITTEST_NAME} ${UNITTEST_NAME}.cpp ${TC_SOURCES} ${NSD_MOCK_SRCS})
+FILE(GLOB GTEST_SRCS ${CMAKE_SOURCE_DIR}/src/dns-sd/*.c ${CMAKE_SOURCE_DIR}/src/ssdp/*.c ${UNITTEST_NAME}.cpp ${TC_SOURCES} ${NSD_MOCK_SRCS})
+ADD_EXECUTABLE(${UNITTEST_NAME} ${GTEST_SRCS})
TARGET_LINK_LIBRARIES(${UNITTEST_NAME}
- ${unittest_pkgs_LIBRARIES}
- ${TARGET_LIB_NSD_DNS_SD}
- ${TARGET_LIB_NSD_SSDP}
+ ${unittest_pkgs_LIBRARIES}
dl
)
-INSTALL(TARGETS ${UNITTEST_NAME} RUNTIME DESTINATION ${BIN_DIR})
\ No newline at end of file
+SET_TARGET_PROPERTIES(${UNITTEST_NAME} PROPERTIES
+ COMPILE_FLAGS "-fPIE"
+ LINK_FLAGS "-Wl,\
+--wrap=g_signal_connect_data,\
+--wrap=g_signal_handler_disconnect,\
+--wrap=g_io_channel_unix_new,\
+--wrap=g_io_channel_set_flags,\
+--wrap=g_io_channel_set_close_on_unref,\
+--wrap=g_io_channel_unref,\
+--wrap=g_io_create_watch,\
+--wrap=g_source_set_callback,\
+--wrap=g_source_attach,\
+--wrap=g_source_unref,\
+--wrap=g_source_remove,\
+--wrap=cynara_check")
+
+INSTALL(TARGETS ${UNITTEST_NAME} RUNTIME DESTINATION ${BIN_DIR})
#include <cynara-client.h>
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
-
-API int cynara_check(cynara *p_cynara,
+int __wrap_cynara_check(cynara *p_cynara,
const char *client, const char *client_session,
const char *user, const char *privilege)
{
#include <glib.h>
#include <gio/gio.h>
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
-
#define TIZEN_MOCK_IO_CHANNEL_SOURCE 5
-API GIOChannel *g_io_channel_unix_new(gint fd)
+extern void __real_g_source_set_callback(GSource *source, GSourceFunc func,
+ gpointer data, GDestroyNotify notify);
+extern guint __real_g_source_attach(GSource *source, GMainContext *context);
+
+GIOChannel *__wrap_g_io_channel_unix_new(gint fd)
{
return g_new(GIOChannel, 1);
}
-API GIOStatus g_io_channel_set_flags(GIOChannel *channel,
+GIOStatus __wrap_g_io_channel_set_flags(GIOChannel *channel,
GIOFlags flags,
GError **error)
{
}
-API void g_io_channel_set_close_on_unref(GIOChannel *channel,
+void __wrap_g_io_channel_set_close_on_unref(GIOChannel *channel,
gboolean do_close)
{
return;
}
typedef struct {
- GIOChannel *channel;
GIOFunc func;
gpointer user_data;
gboolean called_once;
if (cb_data->called_once)
return TRUE;
- cb_data->func(cb_data->channel, G_IO_IN, cb_data->user_data);
+ cb_data->func(NULL, G_IO_IN, cb_data->user_data);
cb_data->called_once = TRUE;
return TRUE;
}
-static void __remove_mock_gio_channel_cb(gpointer data)
+GSource *__wrap_g_io_create_watch(GIOChannel *channel, GIOCondition condition)
{
- mock_gio_channel_cb_data_s *cb_data = (mock_gio_channel_cb_data_s *)data;
- if (!cb_data)
- return;
- g_free(cb_data);
+ return g_idle_source_new();
}
-API guint g_io_add_watch(GIOChannel *channel,
- GIOCondition condition,
- GIOFunc func,
- gpointer user_data)
+void __wrap_g_source_set_callback(GSource *source, GSourceFunc func,
+ gpointer data, GDestroyNotify notify)
{
mock_gio_channel_cb_data_s *cb_data = g_try_malloc0(sizeof(mock_gio_channel_cb_data_s));
- guint g_mock_gio_channel_cb_source = 0;
-
- cb_data->channel = channel;
- cb_data->func = func;
- cb_data->user_data = user_data;
cb_data->called_once = FALSE;
- g_mock_gio_channel_cb_source = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
- __mock_gio_channel_cb,
- (gpointer)cb_data,
- __remove_mock_gio_channel_cb);
+ cb_data->func = (GIOFunc)func;
+ cb_data->user_data = data;
+ __real_g_source_set_callback(source, __mock_gio_channel_cb, cb_data, notify);
+}
- return g_mock_gio_channel_cb_source;
+guint __wrap_g_source_attach(GSource *source, GMainContext *context)
+{
+ return __real_g_source_attach(source, context);
+}
+
+void __wrap_g_source_unref(GSource *source)
+{
}
-API gboolean g_source_remove (guint tag)
+gboolean __wrap_g_source_remove(guint tag)
{
GSource *source;
if (tag == 0 || tag > 1000)
return FALSE;
- source = g_main_context_find_source_by_id (NULL, tag);
+ source = g_main_context_find_source_by_id(NULL, tag);
if (source)
- g_source_destroy (source);
+ g_source_destroy(source);
else
printf("Source ID %u was not found when attempting to remove it\n", tag);
return source != NULL;
}
-API void g_io_channel_unref(GIOChannel *channel)
+void __wrap_g_io_channel_unref(GIOChannel *channel)
{
g_free(channel);
}
else
return 1;
}
-API gulong g_signal_connect_data(gpointer instance,
+API gulong __wrap_g_signal_connect_data(gpointer instance,
const gchar *detailed_signal,
GCallback c_handler,
gpointer data,
return DEFAULT_MOCK_GOBJECT_SIGNAL;
}
-API void g_signal_handler_disconnect (gpointer instance, gulong handler_id)
+API void __wrap_g_signal_handler_disconnect (gpointer instance, gulong handler_id)
{
return;
}