Increase line coverage using LCOV_EXCL
[platform/core/system/libstorage.git] / src / storage-external-dbus.c
index b94e311..5a23bc6 100755 (executable)
 
 #define DBUS_REPLY_TIMEOUT (-1)
 
+#define GET_DBUS_CONN_OR_EXIT() \
+       ({ \
+               dbus_handle_h dbus_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, true); \
+               if (dbus_handle == NULL) { \
+                       _E("Failed to get dbus connection"); \
+                       return -EIO; \
+               } \
+               dbus_handle; \
+       })
+
+
 struct storage_ext_callback {
        storage_ext_changed_cb func;
        void *data;
@@ -104,21 +115,29 @@ int storage_ext_get_list(GList **list)
        if (!list)
                return -EINVAL;
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        STORAGE_EXT_GET_LIST,
                        g_variant_new("(s)", "all"),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
-               return -EIO;
+               return -EIO; //LCOV_EXCL_LINE
        }
 
        if (!g_variant_get_safe(reply, "(a(issssssisibii))", &iter)) {
+               //LCOV_EXCL_START Dbus type error
                _E("Failed to get params from gvariant.");
                g_variant_unref(reply);
                return -EIO;
+               //LCOV_EXCL_STOP
        }
 
        while (g_variant_iter_loop(iter, "(issssssisibii)",
@@ -131,9 +150,11 @@ int storage_ext_get_list(GList **list)
 
                elem = (storage_ext_device *)malloc(sizeof(storage_ext_device));
                if (!elem) {
-                       _E("malloc() failed"); //LCOV_EXCL_LINE
+                       //LCOV_EXCL_START System error
+                       _E("malloc() failed");
                        ret = -ENOMEM;
                        goto out;
+                       //LCOV_EXCL_STOP
                }
 
                elem->type = info.type;
@@ -173,15 +194,21 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf)
 
        memset(buf, 0, sizeof(struct statvfs_32));
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
                        g_variant_new("(s)", path),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
-               return -EIO;
+               return -EIO; //LCOV_EXCL_LINE
        }
 
        if (!g_variant_get_safe(reply, "(ttttttttttt)",
@@ -220,15 +247,21 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
 
        memset(buf, 0, sizeof(struct statvfs));
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STATVFS,
                        g_variant_new("(s)", path),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE
-               return -EIO;
+               return -EIO; //LCOV_EXCL_LINE
        }
 
        if (!g_variant_get_safe(reply, "(ttttttttttt)",
@@ -236,9 +269,11 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf)
                        &(buf->f_bfree), &(buf->f_bavail), &(buf->f_files),
                        &(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid),
                        &(buf->f_flag), &(buf->f_namemax))) {
+               //LCOV_EXCL_START Dbus type error
                _E("Failed to get params from gvariant.");
                g_variant_unref(reply);
                return -EIO;
+               //LCOV_EXCL_STOP
        }
 
 //     %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax
@@ -265,21 +300,32 @@ int storage_ext_get_storage_level(const char *path, char **level)
                return -EINVAL;
        }
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(
+                       dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_STORAGE,
                        STORAGE_EXT_IFACE_STORAGE,
                        STORAGE_EXT_GET_STORAGE_LEVEL,
                        g_variant_new("(i)", id),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
+               //LCOV_EXCL_START Dbus error
                _E("Failed to get %d level", id);
                return -EIO;
+               //LCOV_EXCL_STOP
        }
 
        if (!g_variant_get_safe(reply, "(s)", &reply_val)) {
+               //LCOV_EXCL_START Dbus type error
                _E("Failed to get params from gvariant.");
                g_variant_unref(reply);
                return -EIO;
+               //LCOV_EXCL_STOP
        }
 
        *level = strdup(reply_val);
@@ -287,7 +333,7 @@ int storage_ext_get_storage_level(const char *path, char **level)
        g_variant_unref(reply);
 
        if (*level == NULL)
-               return -ENOMEM;
+               return -ENOMEM; //LCOV_EXCL_LINE
 
        return 0;
 }
@@ -455,15 +501,21 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
        GVariant *reply;
        int ret_dbus;
 
-       ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME,
+       dbus_handle_h dbus_handle = GET_DBUS_CONN_OR_EXIT();
+
+       ret_dbus = gdbus_priv_call_sync_with_reply(dbus_handle,
+                       STORAGE_EXT_BUS_NAME,
                        STORAGE_EXT_PATH_MANAGER,
                        STORAGE_EXT_IFACE_MANAGER,
                        "GetDeviceInfo",
                        g_variant_new("(i)", storage_id),
                        &reply);
+
+       gdbus_free_connection(dbus_handle);
+
        if (ret_dbus < 0) {
                _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
-               return -ENODEV;
+               return -ENODEV; //LCOV_EXCL_LINE
        }
 
        if (!g_variant_get_safe(reply, "(issssssisibii)",
@@ -473,15 +525,19 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info)
                                &info->readonly, &info->mount_point,
                                &info->state, &info->primary,
                                &info->flags, &info->storage_id)) {
-               _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
+               //LCOV_EXCL_START Dbus error
+               _E("No storage with the storage id (%d)", storage_id);
                ret_dbus = -ENODEV;
                goto out;
+               //LCOV_EXCL_STOP
        }
 
        if (info->storage_id < 0) {
-               _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE
+               //LCOV_EXCL_START Dbus error
+               _E("No storage with the storage id (%d)", storage_id);
                ret_dbus = -ENODEV;
                goto out;
+               //LCOV_EXCL_STOP
        }
 
 out: