#include <gmock/gmock.h>
#include <bundle_cpp.h>
#include <bundle_internal.h>
+#include <pkgmgr-info.h>
#include <iostream>
#include <memory>
return 0;
}
+extern "C" void g_object_unref(gpointer _object) {
+}
+
+extern "C" gboolean g_source_remove(guint tag) {
+ return true;
+}
+
+extern "C" int aul_request_message_port_socket_pair(int* fd) {
+ fd[0] = 77;
+ fd[1] = 777;
+ return 0;
+}
+
+extern "C" int pthread_mutex_lock(pthread_mutex_t* mutex) {
+ return 0;
+}
+
+extern "C" int pthread_mutex_unlock(pthread_mutex_t* mutex) {
+ return 0;
+}
+
extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int len) {
char test[5] = "test";
snprintf(appid, sizeof(test), "%s", test);
return 0;
}
+extern "C" gint g_unix_fd_list_append(GUnixFDList* list,
+ gint fd, GError** error) {
+ return 0;
+}
+
+extern "C" int pkgmgrinfo_appinfo_get_usr_appinfo(const char* appid, uid_t uid,
+ pkgmgrinfo_appinfo_h* handle) {
+ return 0;
+}
+
+extern "C" int pkgmgrinfo_appinfo_is_preload(
+ pkgmgrinfo_appinfo_h handle, bool* preload) {
+ *preload = false;
+ return 0;
+}
+
+extern "C" int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle) {
+ return 0;
+}
+
+extern "C" int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
+ const char* lhs_app_id, const char* rhs_app_id, uid_t uid,
+ pkgmgrinfo_cert_compare_result_type_e* compare_result) {
+ *compare_result = PMINFO_CERT_COMPARE_MATCH;
+ return 0;
+}
+
+GVariant* __call_sync_reply;
extern "C" 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 (__call_sync_reply != nullptr)
+ return __call_sync_reply;
return g_variant_new("(u)", 1);
}
bool trusted_remote_port, bundle* message, void* user_data) {
}
+struct _GDBusMessage {
+ int test;
+};
+typedef struct _GDBusMessage GDBusMessage;
+GDBusMessage __message;
+
+typedef struct _GUnixFDList GUnixFDList;
+struct _GUnixFDList {
+ int test;
+};
+GUnixFDList __fd_list;
+extern "C" GUnixFDList* g_dbus_message_get_unix_fd_list(
+ GDBusMessage* message) {
+ return &__fd_list;
+}
+
typedef struct _GDBusConnection GDBusConnection;
struct _GDBusConnection {
int test;
};
GDBusConnection __gdbus_conn;
+int __port_id;
+static guint __connection_register_object(GDBusConnection* connection,
+ const gchar* object_path, GDBusInterfaceInfo* interface_info,
+ const GDBusInterfaceVTable* vtable, gpointer user_data,
+ GDestroyNotify user_data_free_func, GError** error) {
+ tizen_base::Bundle msg;
+ vtable->method_call(&__gdbus_conn, "sender", "obj_path", "iface_name",
+ "send_message",
+ g_variant_new("(ssbbssbus)", "test", "PORT", 0, 0, "test",
+ "PORT", 0, msg.ToRaw().second, msg.ToRaw().first.get()),
+ nullptr, nullptr);
+ return __port_id;
+}
+
TEST_F(MessagePortTest, message_port_register_local_port) {
EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _)).
WillOnce(Return(&__gdbus_conn));
int port = message_port_register_local_port("PORT", __message_cb, nullptr);
EXPECT_EQ(port, 1);
+ 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);
}
TEST_F(MessagePortTest, message_port_register_trusted_local_port) {
EXPECT_EQ(port, 2);
}
+TEST_F(MessagePortTest, message_port_register_trusted_local_port_n) {
+ int port = message_port_register_trusted_local_port(
+ nullptr, __message_cb, nullptr);
+ EXPECT_EQ(port, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_trusted_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_trusted_message_with_local_port(
+ "test", "PORT", message.GetHandle(), 1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_send_trusted_message_with_local_port_n1) {
+ int ret = message_port_send_trusted_message_with_local_port(
+ nullptr, "PORT", nullptr, 1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_trusted_message_with_local_port_n2) {
+ tizen_base::Bundle message;
+ int ret = message_port_send_trusted_message_with_local_port(
+ "test", "PORT", message.GetHandle(), -1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_send_trusted_message) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_message_new_method_call(_, _, _, _)).
+ WillOnce(Return(&__message));
+
+ tizen_base::Bundle message;
+ int ret = message_port_send_trusted_message(
+ "test", "PORT", message.GetHandle());
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_send_trusted_message_n) {
+ int ret = message_port_send_trusted_message(nullptr, "PORT", nullptr);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
TEST_F(MessagePortTest, message_port_unregister_local_port) {
int ret = message_port_unregister_local_port(1);
EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}
+TEST_F(MessagePortTest, message_port_unregister_local_port_n) {
+ int ret = message_port_unregister_local_port(-1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
TEST_F(MessagePortTest, message_port_unregister_trusted_local_port) {
int ret = message_port_unregister_trusted_local_port(2);
EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}
+
+TEST_F(MessagePortTest, message_port_unregister_trusted_local_port_n) {
+ int ret = message_port_unregister_trusted_local_port(-1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_check_remote_port) {
+ bool exist;
+ int ret = message_port_check_remote_port("test", "test", &exist);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_check_remote_port_n) {
+ bool exist;
+ int ret = message_port_check_remote_port(nullptr, "test", &exist);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_check_trusted_remote_port) {
+ if (__call_sync_reply != nullptr)
+ g_variant_unref(__call_sync_reply);
+ __call_sync_reply = g_variant_new("(b)", true);
+
+ tizen_base::Bundle message;
+ bool exist;
+ int ret = message_port_check_trusted_remote_port("test2", "PORT", &exist);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_check_trusted_remote_port_n) {
+ bool exist;
+ int ret = message_port_check_trusted_remote_port(nullptr, "PORT", &exist);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+static void __registration_event_cb(const char* remote_app_id,
+ const char* remote_port, bool trusted_remote_port, void* user_data) {
+}
+
+TEST_F(MessagePortTest, message_port_add_registered_cb) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).WillOnce(
+ Invoke(__g_bus_watch_name_on_connection));
+ int watcher_id;
+ int ret = message_port_add_registered_cb("test", "PORT", false,
+ __registration_event_cb, nullptr, &watcher_id);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_add_registered_cb_n) {
+ int watcher_id;
+ int ret = message_port_add_registered_cb(nullptr, "PORT", false,
+ __registration_event_cb, nullptr, &watcher_id);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_add_unregistered_cb) {
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).WillOnce(Return(2));
+ int watcher_id;
+ int ret = message_port_add_unregistered_cb("test", "PORT", false,
+ __registration_event_cb, nullptr, &watcher_id);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_add_unregistered_cb_n) {
+ int watcher_id;
+ int ret = message_port_add_unregistered_cb(nullptr, "PORT", false,
+ __registration_event_cb, nullptr, &watcher_id);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MessagePortTest, message_port_remove_registration_event_cb) {
+ int ret = message_port_remove_registration_event_cb(10);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
+}
+
+TEST_F(MessagePortTest, message_port_remove_registration_event_cb_n) {
+ int ret = message_port_remove_registration_event_cb(-1);
+ EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
+}