+ port = message_port_register_local_port("PORT", __message_cb, nullptr);
+ EXPECT_EQ(port, 1);
+}
+
+extern "C" gint* g_unix_fd_list_steal_fds(GUnixFDList* list, gint* length) {
+ gint* fds = (gint*)calloc(2, sizeof(gint));
+ fds[0] = 1;
+ fds[1] = 2;
+ return fds;
+}
+
+GIOChannel __gio_channel;
+extern "C" GIOChannel* g_io_channel_unix_new(gint fd) {
+ return &__gio_channel;
+}
+
+GIOFunc __io_func;
+gpointer __io_data;
+GDestroyNotify __io_notify;
+extern "C" guint g_io_add_watch_full(GIOChannel* channel, gint priority,
+ GIOCondition condition, GIOFunc func, gpointer user_data,
+ GDestroyNotify notify) {
+ __io_func = func;
+ __io_data = user_data;
+ __io_notify = notify;
+ return 1;
+}
+
+extern "C" GIOStatus g_io_channel_shutdown(GIOChannel* channel,
+ gboolean flush, GError** err) {
+ return G_IO_STATUS_NORMAL;
+}
+
+extern "C" void g_io_channel_unref(GIOChannel* channel) {
+}
+
+extern "C" gint g_io_channel_unix_get_fd(GIOChannel* channel) {
+ return 1;
+}
+
+extern "C" int read(int desc, void* buf, size_t count) {
+ if (count == 4 && buf != NULL) {
+ int val = 4;
+ memcpy(buf, &val, count);
+ }
+ return count;
+}
+
+extern "C" ssize_t write(int fd, const void* buf, size_t count) {
+ return count;
+}
+
+guint __g_bus_watch_name_on_connection(GDBusConnection* connection,
+ const gchar* name, GBusNameWatcherFlags flags,
+ GBusNameAppearedCallback name_appeared_handler,
+ GBusNameVanishedCallback name_vanished_handler,
+ gpointer user_data,
+ GDestroyNotify user_data_free_func) {
+ int* id = NULL;
+ name_appeared_handler(nullptr, "test", "test", (gpointer)id);
+ name_vanished_handler(nullptr, "test", (gpointer)id);
+ return 10;
+}
+
+TEST_F(MessagePortTest, message_port_register_local_port2) {
+ GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
+ malloc(sizeof(GDBusNodeInfo)));
+ info->ref_count = 10;
+ info->path = NULL;
+ info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
+ malloc(sizeof(GDBusInterfaceInfo*)));
+ info->nodes = NULL;
+ info->annotations = NULL;
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_register_object(_, _, _, _, _, _, _)).
+ WillOnce(Invoke(__connection_register_object));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).
+ WillOnce(Invoke(__g_bus_watch_name_on_connection));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
+ WillOnce(Return(&__message));
+
+ __port_id = 10;
+ int port = message_port_register_local_port("PORT2", __message_cb, nullptr);
+ EXPECT_EQ(port, __port_id);
+ __io_func(nullptr, G_IO_IN, __io_data);
+}
+
+TEST_F(MessagePortTest, message_port_register_local_port3) {
+ GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
+ malloc(sizeof(GDBusNodeInfo)));
+ info->ref_count = 10;
+ info->path = NULL;
+ info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
+ malloc(sizeof(GDBusInterfaceInfo*)));
+ info->nodes = NULL;
+ info->annotations = NULL;
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_register_object(_, _, _, _, _, _, _)).
+ WillOnce(Invoke(__connection_register_object));
+
+ __port_id = 20;
+ int port = message_port_register_local_port("PORT3", __message_cb, nullptr);
+ EXPECT_EQ(port, __port_id);
+ __io_notify(__io_data);
+}
+
+TEST_F(MessagePortTest, message_port_register_local_port_n) {
+ int port = message_port_register_local_port(nullptr, __message_cb, nullptr);
+ EXPECT_EQ(port, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_message) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+
+ tizen_base::Bundle message;
+ int ret = message_port_send_message("test", "PORT", message.GetHandle());
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_n) {
+ int ret = message_port_send_message(nullptr, "PORT", nullptr);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_with_local_port) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+
+ tizen_base::Bundle message;
+ int ret = message_port_send_message_with_local_port(
+ "test", "PORT", message.GetHandle(), 1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_with_local_port_n1) {
+ int ret = message_port_send_message_with_local_port(
+ nullptr, "PORT", nullptr, 1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_with_local_port_n2) {
+ tizen_base::Bundle message;
+ int ret = message_port_send_message_with_local_port(
+ "test", "PORT", message.GetHandle(), -1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_with_local_port2) {
+ if (__call_sync_reply != nullptr)
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = g_variant_new("(b)", true);
+
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+ tizen_base::Bundle message;
+ int ret = message_port_send_message_with_local_port(
+ "remote_app", "PORT", message.GetHandle(), 1);
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = nullptr;
+
+ ret = message_port_send_message_with_local_port(
+ "remote_app", "PORT", message.GetHandle(), 1);
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = nullptr;
+
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+ __io_func(nullptr, G_IO_IN, __io_data);
+}
+
+TEST_F(MessagePortTest, message_port_send_message_with_local_port3) {
+ if (__call_sync_reply != nullptr)
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = g_variant_new("(b)", true);
+
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+ tizen_base::Bundle message;
+ int ret = message_port_send_message_with_local_port(
+ "remote_app", "PORT", message.GetHandle(), 1);
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = nullptr;
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+ __io_notify(__io_data);