Added Gtest for mtp-initiator and Gcov coverage 15/191115/4 accepted/tizen/5.0/unified/20181102.015202 accepted/tizen/unified/20181014.114259 submit/tizen/20181012.075351 submit/tizen_5.0/20181101.000003
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Thu, 11 Oct 2018 10:24:03 +0000 (15:54 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 12 Oct 2018 07:18:14 +0000 (16:18 +0900)
Description:
Overall coverage rate:
  lines......: 96.8% (967 of 999 lines)
  functions..: 100.0% (65 of 65 functions)

Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: I662ef7232698b78c66805ab9e0dc730bbe866e31

20 files changed:
CMakeLists.txt
packaging/mtp-initiator.spec
src/daemon/CMakeLists.txt
src/daemon/mtp_daemon.c
src/daemon/mtp_daemon_controller.c
src/daemon/mtp_daemon_db.c
src/daemon/mtp_daemon_event.c
src/daemon/mtp_daemon_gdbus.c
src/daemon/mtp_daemon_gdbus_deviceinfo.c
src/daemon/mtp_daemon_gdbus_manager.c
src/daemon/mtp_daemon_gdbus_objectinfo.c
src/daemon/mtp_daemon_gdbus_storageinfo.c
src/daemon/mtp_daemon_util.c
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/common.h [new file with mode: 0644]
unittest/gdbus.cpp [new file with mode: 0644]
unittest/gdbus.h [new file with mode: 0644]
unittest/mtp_initiator.cpp [new file with mode: 0644]
unittest/mtp_initiator.h [new file with mode: 0644]
unittest/unittest.cpp [new file with mode: 0644]

index b4e1582a3691db2a7e291765e097e1e1ebaf08e3..4eb9aea1c05f2c80950cab71cd875ea8fcf9fcf0 100644 (file)
@@ -4,8 +4,15 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(LIBDIR "${PREFIX}/lib")
 SET(MODULEDIR "${LIBDIR}/mtp")
 
+IF(BUILD_GCOV)
+       ADD_DEFINITIONS(-DBUILD_GCOV)
+ENDIF(BUILD_GCOV)
+
 ADD_SUBDIRECTORY(src/daemon)
 ADD_SUBDIRECTORY(haltest)
+IF(BUILD_GTESTS)
+       ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
 
 IF(DEFINED TIZEN_ENGINEER_MODE)
        #ADD_SUBDIRECTORY(src/test)
index cb30b1a5ef40e40469160f71004e396172946349..0586716a7bbc7fd87c73587a09c6780399abb4f8 100644 (file)
@@ -22,6 +22,10 @@ BuildRequires:  python
 BuildRequires:  python-xml
 Requires:  security-config
 
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(gmock)
+%endif
+
 %define upgrade_script_path /usr/share/upgrade/scripts
 
 %description
@@ -44,9 +48,18 @@ TIZEN MTP Initiator extension for HAL test.
 cp %{SOURCE1} .
 
 %build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov "
+%endif
+
 CFLAGS+=" -DTIZEN_EXT"
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF}
+%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF} \
+                   -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+                   -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
+
 
 make %{?jobs:-j%jobs}
 
@@ -88,6 +101,9 @@ install -D -m 0644 packaging/mtp-initiator.service %{buildroot}/%{_unitdir}/mtp-
 %{_unitdir}/mtp-initiator.service
 %{_prefix}/lib/udev/rules.d/99-mtp.rules
 %config %{_sysconfdir}/dbus-1/system.d/org.tizen.mtp.conf
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%endif
 
 %files haltests
 %manifest %{name}.manifest
index 91d924f6113bf3c3b362a6e74f2ce2c8cd3b9acd..f95febd10dcf5173b7e89540a93c79b38a2cf35d 100755 (executable)
@@ -37,6 +37,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -pie -Wl,--hash-style=both")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${mtp_pkgs_LDFLAGS} pthread)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${mtp_pkgs_LDFLAGS} pthread -lgcov)
 
 INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
index 6454f2f72d277c52444e0376f51283a616f02471..be96628f3234669d6b7c4e9ed5cff17b36b2da92 100755 (executable)
 #include "mtp_daemon_event.h"
 #include "mtp_daemon_db.h"
 
+#if (BUILD_GCOV != 0)
+extern void __gcov_flush(void);
+#endif
+
 static mtp_context *_mtp_ctx = NULL;
 
 static mtp_error_e __daemon_initalize(mtp_context *mtp_ctx)
@@ -30,31 +34,40 @@ static mtp_error_e __daemon_initalize(mtp_context *mtp_ctx)
 
        ret = mtp_daemon_controller_init(mtp_ctx);
        if (ret != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("mtp_daemon_controller_init is failed: %d", ret);
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        ret = mtp_daemon_db_init(mtp_ctx);
        if (ret != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("mtp_daemon_db_init is failed: %d", ret);
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        ret = mtp_daemon_event_init(mtp_ctx);
        if (ret != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("mtp_daemon_event_init is failed: %d", ret);
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        ret = mtp_daemon_gdbus_init(mtp_ctx);
        if (ret != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("mtp_daemon_gdbus_init is failed: %d", ret);
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        return ret;
 }
 
+/* LCOV_EXCL_START */
 static mtp_error_e __daemon_deinitalize(mtp_context *mtp_ctx)
 {
        mtp_error_e ret = MTP_ERROR_NONE;
@@ -86,11 +99,17 @@ static mtp_error_e __daemon_deinitalize(mtp_context *mtp_ctx)
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 static void __mtp_signal_handler(int signo)
 {
        gint ret;
 
+#if (BUILD_GCOV != 0)
+       __gcov_flush();
+       MTP_LOGI("Flushed gcov data");
+#endif
+
        if (!_mtp_ctx)
                return;
 
@@ -124,18 +143,18 @@ int main(int argc, char *argv[])
        sigemptyset(&sigact.sa_mask);
        sigact.sa_flags = 0;
        if (sigaction(SIGTERM, &sigact, NULL) < 0)
-               MTP_LOGW("sigaction is failed");
+               MTP_LOGW("sigaction is failed"); //LCOV_EXCL_LINE
 
        /* 2. create mtp daemon context */
        mtp_ctx = g_new0(mtp_context, 1);
        if (!mtp_ctx) {
-               MTP_LOGE("create mtp_context is failed");
+               MTP_LOGE("create mtp_context is failed"); //LCOV_EXCL_LINE
                goto EXIT;
        }
 
        mtp_ctx->device_list = g_new0(mtp_device_list, 1);
        if (mtp_ctx->device_list == NULL) {
-               MTP_LOGE("create device_list is failed");
+               MTP_LOGE("create device_list is failed"); //LCOV_EXCL_LINE
                goto EXIT;
        }
 
@@ -150,19 +169,25 @@ int main(int argc, char *argv[])
        /* 3. initialize daemon */
        ret = __daemon_initalize(mtp_ctx);
        if (ret != MTP_ERROR_NONE) {
-               MTP_LOGE("daemon initalize is failed");
+               MTP_LOGE("daemon initalize is failed"); //LCOV_EXCL_LINE
                goto EXIT;
        }
 
        g_main_loop_run(mtp_ctx->main_loop);
 
 EXIT:
+       /* LCOV_EXCL_START */
        ret = __daemon_deinitalize(mtp_ctx);
        if (ret != MTP_ERROR_NONE)
-               MTP_LOGE("daemon deinitalize is failed");
+               MTP_LOGE("daemon deinitalize is failed"); //LCOV_EXCL_LINE
+
+#if (BUILD_GCOV != 0)
+       __gcov_flush();
+#endif
 
        MTP_LOGE("mtp initiator exit");
 
        return 0;
+       /* LCOV_EXCL_STOP */
 }
 
index 003093d5e4bd7dda918ca9b071818d80f5348fbc..ab31db0984b71746ffa39594002f3c3cae5dc0f0 100755 (executable)
 
 #include "mtp_daemon_controller.h"
 
+/* LCOV_EXCL_START */
 static void _controller_queue_free(gpointer user_data)
 {
        mtp_queue_data* data = (mtp_queue_data*)user_data;
        if (data != NULL)
                g_free(data);
 }
+/* LCOV_EXCL_STOP */
 
 static gpointer _controller_thread(gpointer user_data)
 {
        mtp_context* mtp_ctx = (mtp_context*)user_data;
 
        if (mtp_ctx == NULL || mtp_ctx->c_queue == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("create thread failed");
                g_thread_exit(NULL);
 
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_ctx->is_running = true;
@@ -51,9 +55,9 @@ static gpointer _controller_thread(gpointer user_data)
                _controller_queue_free(data);
        }
 
-       g_thread_exit(NULL);
+       g_thread_exit(NULL); //LCOV_EXCL_LINE
 
-       return NULL;
+       return NULL; //LCOV_EXCL_LINE
 }
 
 mtp_error_e mtp_daemon_controller_push(mtp_controller_func func,
@@ -67,8 +71,10 @@ mtp_error_e mtp_daemon_controller_push(mtp_controller_func func,
        RETV_IF(mtp_ctx->c_queue == NULL, MTP_ERROR_INVALID_PARAMETER);
 
        if (mtp_ctx->is_releasing == true) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("controller queue is busy now");
                return MTP_ERROR_CONTROLLER;
+               /* LCOV_EXCL_STOP */
        }
 
        data = g_new0(mtp_queue_data, 1);
@@ -91,6 +97,7 @@ mtp_error_e mtp_daemon_controller_init(mtp_context *mtp_ctx)
        mtp_ctx->c_thread = g_thread_try_new(NULL, _controller_thread, mtp_ctx, &error);
 
        if (mtp_ctx->c_thread == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Can not create controller thread");
                if (error != NULL) {
                        MTP_LOGE("The error msg: %s", error->message);
@@ -98,6 +105,7 @@ mtp_error_e mtp_daemon_controller_init(mtp_context *mtp_ctx)
                }
 
                return MTP_ERROR_CONTROLLER;
+               /* LCOV_EXCL_STOP */
        }
 
        return ret;
index 59bd49913fad5714660d6dcfbd51cfefd58cb478..51febd5826ac8d38b1e50ecc135a50a013f26ecb 100755 (executable)
@@ -16,6 +16,7 @@
 
 #include "mtp_daemon_db.h"
 
+/* LCOV_EXCL_START */
 mtp_error_e mtp_daemon_db_delete(int mtp_device, int mtp_storage,
        int object_handle, mtp_context *mtp_ctx)
 {
@@ -312,6 +313,7 @@ mtp_error_e mtp_daemon_db_insert(int mtp_device, int mtp_storage,
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 static mtp_error_e __create_table(mtp_context *mtp_ctx)
 {
@@ -321,8 +323,10 @@ static mtp_error_e __create_table(mtp_context *mtp_ctx)
        char *error = NULL;
 
        if (mtp_ctx->db == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("mtp_ctx->db is NULL");
                return MTP_ERROR_DB;
+               /* LCOV_EXCL_STOP */
        }
 
        sql = sqlite3_mprintf("CREATE TABLE %s(id INTEGER PRIMARY KEY, mtp_device INTEGER, mtp_storage INTEGER, object_handle INTEGER, ObjectFormat INTEGER, ProtectionStatus INTEGER, ObjectCompressedSize INTEGER, ThumbFormat INTEGER, ThumbCompressedSize INTEGER, ThumbPixWidth INTEGER, ThumbPixHeight INTEGER, ImagePixWidth INTEGER, ImagePixHeight INTEGER, ImageBitDepth INTEGER, ParentObject INTEGER, AssociationType INTEGER, AssociationDesc INTEGER, SequenceNumber INTEGER, Filename TEXT, CaptureDate INTEGER, ModificationDate INTEGER, Keywords TEXT);",
@@ -331,13 +335,15 @@ static mtp_error_e __create_table(mtp_context *mtp_ctx)
        if (sql != NULL) {
                sql_ret = sqlite3_exec(mtp_ctx->db, sql, NULL, NULL, &error);
                if (sql_ret != SQLITE_OK) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("sqlite3_exec failed, %d, %s", sql_ret, error);
                        ret = MTP_ERROR_DB;
                        sqlite3_free(error);
+                       /* LCOV_EXCL_STOP */
                }
                sqlite3_free(sql);
        } else {
-               MTP_LOGE("sql is NULL");
+               MTP_LOGE("sql is NULL"); //LCOV_EXCL_LINE
                ret = MTP_ERROR_DB;
        }
 
@@ -363,6 +369,7 @@ mtp_error_e mtp_daemon_db_init(mtp_context *mtp_ctx)
        return ret;
 }
 
+/* LCOV_EXCL_START */
 mtp_error_e mtp_daemon_db_deinit(mtp_context *mtp_ctx)
 {
        int ret = MTP_ERROR_NONE;
@@ -379,3 +386,4 @@ mtp_error_e mtp_daemon_db_deinit(mtp_context *mtp_ctx)
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
index 2ee290001c492bcc15c8c3926ecc14679d2dd0a5..cfd2488b4e0b5612568ea11aafec0488e21d6fa7 100755 (executable)
@@ -19,6 +19,7 @@
 #include "mtp_daemon_db.h"
 #include "mtp_daemon_util.h"
 
+/* LCOV_EXCL_START */
 static void __print_device_list(mtp_context *mtp_ctx)
 {
        int slot;
@@ -33,6 +34,7 @@ static void __print_device_list(mtp_context *mtp_ctx)
                }
        }
 }
+/* LCOV_EXCL_STOP */
 
 static int __search_empty_slot(mtp_context *mtp_ctx)
 {
@@ -61,6 +63,7 @@ static void __wait_smack_labeling(char *usb_node)
        } while (check_count++ < 100);
 }
 
+/* LCOV_EXCL_START */
 int __usb_host_status_changed_cb(struct libusb_context *ctx,
        struct libusb_device *dev, libusb_hotplug_event event, void *user_data)
 {
@@ -170,6 +173,7 @@ int __usb_host_status_changed_cb(struct libusb_context *ctx,
 
        return 0;
 }
+/* LCOV_EXCL_STOP */
 
 static void* __event_thread(gpointer dev, gpointer data)
 {
@@ -182,7 +186,7 @@ static void* __event_thread(gpointer dev, gpointer data)
 
        device_id = mtp_daemon_util_get_device_id(device, mtp_ctx);
        if (device_id < 0)
-               return NULL;
+               return NULL; //LCOV_EXCL_LINE
 
        device_info = mtp_ctx->device_list->device_info_list[device_id];
        if (device_info == NULL)
@@ -192,6 +196,7 @@ static void* __event_thread(gpointer dev, gpointer data)
                device_info->bus_location, device_info->device_number);
 
        while (LIBMTP_Read_Event(device, &device_event, &param1) == 0) {
+               /* LCOV_EXCL_START */
                MTP_LOGI("%s, %03d-%03d event occurs", device_info->model_name,
                        device_info->bus_location, device_info->device_number);
 
@@ -219,6 +224,7 @@ static void* __event_thread(gpointer dev, gpointer data)
                        g_free(object_info);
                }
                mtp_daemon_gdbus_emit_event(device_event, (int)param1, mtp_ctx);
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("%s, %03d-%03d event loop stop", device_info->model_name,
@@ -241,9 +247,11 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
        LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices);
 
        if (numrawdevices == 0) {
+               /* LCOV_EXCL_START */
                MTP_LOGW("MTP Host have not any mtp device");
                g_free(rawdevices);
                return MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        for (device_index = 0; device_index < numrawdevices; device_index++) {
@@ -254,8 +262,10 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
 
                empty_slot = __search_empty_slot(mtp_ctx);
                if (empty_slot < 0) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("Not enough space in device_list");
                        continue;
+                       /* LCOV_EXCL_STOP */
                }
 
                snprintf(usb_node, sizeof(usb_node), "/dev/bus/usb/%03d/%03d",
@@ -265,8 +275,10 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
 
                device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[device_index]);
                if (device == NULL) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("Unable to open raw device : %s", usb_node);
                        continue;
+                       /* LCOV_EXCL_STOP */
                }
 
                device_info = g_new0(mtp_device_info, 1);
@@ -279,15 +291,17 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
 
                MTP_LOGI("Device version : %s", device_version);
                if (!strncmp(device_version, "SM", 2) && strlen(device_version) > 25) {
+                       /* LCOV_EXCL_START */
                        device_info->stitching_engine_version = g_strndup(&device_version[21], 4);
                        MTP_LOGI("stitching engine version : %s", device_info->stitching_engine_version);
+                       /* LCOV_EXCL_STOP */
                }
 
                g_free(device_version);
                device_version = NULL;
 
                if (device_info->model_name == NULL)
-                       device_info->model_name = strdup(tmp_name);
+                       device_info->model_name = strdup(tmp_name); //LCOV_EXCL_LINE
 
                mtp_ctx->device_list->device_info_list[empty_slot] = device_info;
                mtp_ctx->device_list->device_num++;
@@ -302,10 +316,12 @@ static gpointer __dispatch_event(gpointer user_data)
        mtp_context* mtp_ctx = (mtp_context*)user_data;
 
        if (mtp_ctx == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("create thread failed");
                g_thread_exit(NULL);
 
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGE("dispatch thread created");
@@ -337,8 +353,10 @@ mtp_error_e mtp_daemon_event_init(mtp_context *mtp_ctx)
        /* usb event setting */
        ret = libusb_init(&(mtp_ctx->usb_ctx));
        if (ret != LIBUSB_SUCCESS) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("libusb_init failed : %d", ret);
                return MTP_ERROR_PLUGIN_FAIL;
+               /* LCOV_EXCL_STOP */
        }
 
        ret = libusb_hotplug_register_callback(mtp_ctx->usb_ctx,
@@ -349,8 +367,10 @@ mtp_error_e mtp_daemon_event_init(mtp_context *mtp_ctx)
        mtp_ctx->usb_event_thread = g_thread_try_new("dispatch", __dispatch_event, mtp_ctx, NULL);
 
        if (ret != LIBUSB_SUCCESS) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("libusb_hotplug_register_callback failed");
                return MTP_ERROR_PLUGIN_FAIL;
+               /* LCOV_EXCL_STOP */
        }
 
        /* create thread pool */
index c46dbbda0170fbe1c7fbac0a2c478a2108b35f2b..2c576bf5e0b3ae4c9399b66f889023b45e601f5f 100755 (executable)
@@ -89,8 +89,10 @@ static gboolean __manager_init(mtp_context *mtp_ctx)
                mtp_ctx->connection, MTP_DBUS_MANAGER_PATH, &error);
 
        if (ret == FALSE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Can not skeleton_export %s", error->message);
                g_error_free(error);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_ctx->manager = manager_skeleton;
@@ -163,8 +165,10 @@ static gboolean __deviceinfo_init(mtp_context *mtp_ctx)
                mtp_ctx->connection, MTP_DBUS_DEVICEINFO_PATH, &error);
 
        if (ret == FALSE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Can not skeleton_export %s", error->message);
                g_error_free(error);
+               /* LCOV_EXCL_STOP */
        }
 
        return ret;
@@ -224,8 +228,10 @@ static gboolean __storageinfo_init(mtp_context *mtp_ctx)
                mtp_ctx->connection, MTP_DBUS_STORAGEINFO_PATH, &error);
 
        if (ret == FALSE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Can not skeleton_export %s", error->message);
                g_error_free(error);
+               /* LCOV_EXCL_STOP */
        }
 
        return ret;
@@ -266,8 +272,10 @@ static gboolean __objectinfo_init(mtp_context *mtp_ctx)
                 mtp_ctx->connection, MTP_DBUS_OBJECTINFO_PATH, &error);
 
        if (ret == FALSE) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Can not skeleton_export %s", error->message);
                g_error_free(error);
+               /* LCOV_EXCL_STOP */
        }
 
        return ret;
@@ -282,19 +290,19 @@ static void on_bus_acquired(GDBusConnection *connection,
        mtp_ctx->connection = connection;
 
        if (__manager_init(mtp_ctx) == FALSE) {
-               MTP_LOGE("Can not signal connect");
+               MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
                /* Deinitialize and quit daemon */
        }
        if (__deviceinfo_init(mtp_ctx) == FALSE) {
-               MTP_LOGE("Can not signal connect");
+               MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
                /* Deinitialize and quit daemon */
        }
        if (__storageinfo_init(mtp_ctx) == FALSE) {
-               MTP_LOGE("Can not signal connect");
+               MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
                /* Deinitialize and quit daemon */
        }
        if (__objectinfo_init(mtp_ctx) == FALSE) {
-               MTP_LOGE("Can not signal connect");
+               MTP_LOGE("Can not signal connect"); //LCOV_EXCL_LINE
                /* Deinitialize and quit daemon */
        }
 }
@@ -319,12 +327,14 @@ static void on_name_acquired(GDBusConnection *connection,
        }
 }
 
+/* LCOV_EXCL_START */
 static void on_name_lost(GDBusConnection *connnection,
                        const gchar *name,
                        gpointer user_data)
 {
        MTP_LOGE("on_name_lost : %s", name);
 }
+/* LCOV_EXCL_STOP */
 
 mtp_error_e mtp_daemon_gdbus_init(mtp_context *mtp_ctx)
 {
index fb3b9032472711e52072b6bc35ee738758fa3e7b..bb163ecee956b1ebd319d2b32782a23c5892b1b6 100755 (executable)
@@ -44,9 +44,11 @@ static void __deviceinfo_get_manufacturer_name_thread_func(gpointer user_data)
                /* do process */
                name = LIBMTP_Get_Manufacturername(device);
        } else {
+               /* LCOV_EXCL_START */
                name = strdup("N/A");
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("manufacturer name: %s", name);
@@ -89,9 +91,11 @@ static void __deviceinfo_get_model_name_thread_func(gpointer user_data)
                /* do process */
                name = LIBMTP_Get_Modelname(device);
        } else {
+               /* LCOV_EXCL_START */
                name = strdup("N/A");
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("model name: %s", name);
@@ -132,9 +136,11 @@ static void __deviceinfo_get_serial_number_thread_func(gpointer user_data)
                /* do process */
                number = LIBMTP_Get_Serialnumber(device);
        } else {
+               /* LCOV_EXCL_START */
                number = strdup("N/A");
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("serial number: %s", number);
@@ -172,9 +178,11 @@ static void __deviceinfo_get_device_version_thread_func(gpointer user_data)
                /* do process */
                version = LIBMTP_Get_Deviceversion(device);
        } else {
+               /* LCOV_EXCL_START */
                version = strdup("N/A");
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("device version: %s", version);
@@ -211,8 +219,10 @@ static void __deviceinfo_get_bus_location_thread_func(gpointer user_data)
        if (device_info != NULL) {
                bus_location = device_info->bus_location;
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("bus location: %d", bus_location);
@@ -246,8 +256,10 @@ static void __deviceinfo_get_device_number_thread_func(gpointer user_data)
        if (device_info != NULL) {
                device_number = device_info->device_number;
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("device number: %d", device_number);
@@ -282,8 +294,10 @@ static void __deviceinfo_get_stitching_engine_version_thread_func(gpointer user_
                if (device_info->stitching_engine_version != NULL)
                        stitching_engine_version = strdup(device_info->stitching_engine_version);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        MTP_LOGI("stitching_engine_version : %s", stitching_engine_version);
@@ -312,9 +326,11 @@ gboolean deviceinfo_get_manufacturer_name(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -324,21 +340,25 @@ gboolean deviceinfo_get_manufacturer_name(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_manufacturer_name_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_manufacturer_name(deviceinfo,
@@ -358,9 +378,11 @@ gboolean deviceinfo_get_model_name(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -370,21 +392,25 @@ gboolean deviceinfo_get_model_name(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_model_name_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_model_name(deviceinfo, invocation, 0, result);
@@ -403,9 +429,11 @@ gboolean deviceinfo_get_serial_number(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -415,21 +443,25 @@ gboolean deviceinfo_get_serial_number(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_serial_number_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_serial_number(deviceinfo, invocation, 0, result);
@@ -448,9 +480,11 @@ gboolean deviceinfo_get_device_version(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -460,21 +494,25 @@ gboolean deviceinfo_get_device_version(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_device_version_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_device_version(deviceinfo, invocation, 0, result);
@@ -493,9 +531,11 @@ gboolean deviceinfo_get_bus_location(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -505,21 +545,25 @@ gboolean deviceinfo_get_bus_location(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_bus_location_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_bus_location(deviceinfo, invocation, 0, result);
@@ -538,9 +582,11 @@ gboolean deviceinfo_get_device_number(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -550,21 +596,25 @@ gboolean deviceinfo_get_device_number(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_device_number_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_device_number(deviceinfo, invocation, 0, result);
@@ -583,9 +633,11 @@ gboolean deviceinfo_get_stitching_engine_version(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(deviceinfo);
@@ -595,21 +647,25 @@ gboolean deviceinfo_get_stitching_engine_version(
 
        if (mtp_daemon_controller_push(__deviceinfo_get_stitching_engine_version_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
        if (param != NULL) {
+               /* LCOV_EXCL_START */
                g_object_unref(param->invocation);
                g_object_unref(param->object);
 
                g_free(param);
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_deviceinfo_complete_get_stitching_engine_version(deviceinfo, invocation, 0, result);
index b02a82eb05c62261f480017ff871d9c69cf76300..8b08ebb5eaee01152996a72446352e7303b193f9 100755 (executable)
@@ -106,6 +106,7 @@ static void __manager_get_storages_thread_func(gpointer user_data)
        g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
 
        if (device_info != NULL) {
+               /* LCOV_EXCL_START */
                for (storage = device->storage; storage != NULL; storage = storage->next) {
                        g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
 
@@ -116,10 +117,13 @@ static void __manager_get_storages_thread_func(gpointer user_data)
 
                        count++;
                }
+               /* LCOV_EXCL_STOP */
        } else {
                result = MTP_ERROR_NO_DEVICE;
        }
 
+OUT:
+       /* LCOV_EXCL_START */
        gv = g_variant_builder_end(&b);
 
        MTP_LOGI("storage_num: %d", count);
@@ -131,6 +135,7 @@ static void __manager_get_storages_thread_func(gpointer user_data)
        g_object_unref(param->invocation);
        g_object_unref(param->object);
        g_free(param);
+       /* LCOV_EXCL_STOP */
 }
 
 static void __manager_get_object_handles_thread_func(gpointer user_data)
@@ -170,25 +175,33 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
        g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
 
        if (device_id < 0 || param->mtp_ctx->device_list->device_num < device_id) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("device_id : out of range");
                result = MTP_ERROR_NO_DEVICE;
                goto END;
+               /* LCOV_EXCL_STOP */
        }
 
        device_info = (mtp_device_info *)param->mtp_ctx->device_list->device_info_list[device_id];
        if (device_info == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("device_info is NULL");
                result = MTP_ERROR_NO_DEVICE;
                goto END;
+               /* LCOV_EXCL_STOP */
        }
 
        device = (LIBMTP_mtpdevice_t *)device_info->device;
        if (device == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("device is NULL");
                result = MTP_ERROR_NO_DEVICE;
                goto END;
+               /* LCOV_EXCL_STOP */
        }
 
+       /* LCOV_EXCL_START */
+
        MTP_LOGI("device_id: %d, storage id: %d, format: %d, parent: %d",
                param->param1, param->param2, param->param3, param->param4);
 
@@ -241,6 +254,7 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
 
                                g_variant_builder_add(&b, "{sv}", "object_handle",
                                g_variant_new_int32(object_list[slot]));
+                               MTP_LOGI("object %d", object_list[slot]);
 
                                g_variant_builder_close(&b);
 
@@ -267,6 +281,7 @@ END:
        g_object_unref(param->invocation);
        g_object_unref(param->object);
        g_free(param);
+       /* LCOV_EXCL_STOP */
 }
 
 static void __manager_get_object_thread_func(gpointer user_data)
@@ -307,21 +322,27 @@ static void __manager_get_object_thread_func(gpointer user_data)
                fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
 
                if (fd < 0) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
                        result = MTP_ERROR_IO_ERROR;
+                       /* LCOV_EXCL_STOP */
                } else {
                        ret = LIBMTP_Get_File_To_File_Descriptor(device, object_handle, fd, NULL, NULL);
 
                        if (ret != 0) {
+                               /* LCOV_EXCL_START */
                                MTP_LOGE("get descriptor fail - ret: %d", ret);
                                result = MTP_ERROR_PLUGIN_FAIL;
+                               /* LCOV_EXCL_STOP */
                        }
 
                        close(fd);
                }
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_manager_complete_get_object(param->object,
@@ -378,28 +399,34 @@ static void __manager_get_partial_object_thread_func(gpointer user_data)
                fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
 
                if (fd < 0) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
                        result = MTP_ERROR_IO_ERROR;
+                       /* LCOV_EXCL_STOP */
                } else {
                        ret = LIBMTP_GetPartialObject(device, object_handle, (uint32_t)offset, (uint32_t)max_bytes, &data, &actual_written);
 
                        if (ret == 0) {
+                               /* LCOV_EXCL_START */
                                ret = write(fd, data, actual_written);
                                if (ret == 0)
                                        result = MTP_ERROR_OUT_OF_MEMORY;
+                               /* LCOV_EXCL_STOP */
                        } else {
                                MTP_LOGE("get partial object fail - ret: %d", ret);
                                result = MTP_ERROR_PLUGIN_FAIL;
                        }
 
                        if (data != NULL)
-                               free(data);
+                               free(data); //LCOV_EXCL_LINE
 
                        close(fd);
                }
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_manager_complete_get_partial_object(param->object,
@@ -452,8 +479,10 @@ static void __manager_get_thumbnail_thread_func(gpointer user_data)
                fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
 
                if (fd < 0) {
+                       /* LCOV_EXCL_START */
                        MTP_LOGE("file open fail - fd: %d, dest_path: %s", fd, dest_path);
                        result = MTP_ERROR_IO_ERROR;
+                       /* LCOV_EXCL_STOP */
                } else {
                        ret = LIBMTP_Get_Thumbnail_From_Exif_Data(device, object_handle, &thumb_data, &thumb_size);
                        if (ret != 0)
@@ -464,8 +493,10 @@ static void __manager_get_thumbnail_thread_func(gpointer user_data)
                                if (ret == 0)
                                        result = MTP_ERROR_OUT_OF_MEMORY;
                        } else {
+                               /* LCOV_EXCL_START */
                                MTP_LOGE("get thumbnail fail - ret: %d", ret);
                                result = MTP_ERROR_PLUGIN_FAIL;
+                               /* LCOV_EXCL_STOP */
                        }
 
                        if (thumb_data != NULL)
@@ -474,8 +505,10 @@ static void __manager_get_thumbnail_thread_func(gpointer user_data)
                        close(fd);
                }
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_manager_complete_get_thumbnail(param->object,
@@ -520,8 +553,10 @@ static void __manager_delete_object_thread_func(gpointer user_data)
                if (ret != 0)
                        result = MTP_ERROR_PLUGIN_FAIL;
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_manager_complete_delete_object(param->object,
@@ -544,9 +579,11 @@ gboolean manager_get_devices(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -555,16 +592,19 @@ gboolean manager_get_devices(
 
        if (mtp_daemon_controller_push(__manager_get_devices_thread_func, param, param->mtp_ctx)
                != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -575,6 +615,7 @@ OUT:
        mtp_gdbuslib_manager_complete_get_devices(manager, invocation, 0, NULL, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_get_storages(
@@ -588,9 +629,11 @@ gboolean manager_get_storages(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -600,16 +643,19 @@ gboolean manager_get_storages(
 
        if (mtp_daemon_controller_push(__manager_get_storages_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -621,6 +667,7 @@ OUT:
                invocation, 0, NULL, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_get_object_handles(
@@ -637,9 +684,11 @@ gboolean manager_get_object_handles(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -652,16 +701,19 @@ gboolean manager_get_object_handles(
 
        if (mtp_daemon_controller_push(__manager_get_object_handles_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -673,6 +725,7 @@ OUT:
                invocation, 0, NULL, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_get_object(
@@ -688,9 +741,11 @@ gboolean manager_get_object(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -702,16 +757,19 @@ gboolean manager_get_object(
 
        if (mtp_daemon_controller_push(__manager_get_object_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -722,6 +780,7 @@ OUT:
        mtp_gdbuslib_manager_complete_get_object(manager, invocation, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_get_partial_object(
@@ -740,9 +799,11 @@ gboolean manager_get_partial_object(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -756,16 +817,19 @@ gboolean manager_get_partial_object(
 
        if (mtp_daemon_controller_push(__manager_get_partial_object_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -776,6 +840,7 @@ OUT:
        mtp_gdbuslib_manager_complete_get_partial_object(manager, invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_get_thumbnail(
@@ -792,9 +857,11 @@ gboolean manager_get_thumbnail(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -806,16 +873,19 @@ gboolean manager_get_thumbnail(
 
        if (mtp_daemon_controller_push(__manager_get_thumbnail_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -829,6 +899,7 @@ OUT:
        mtp_gdbuslib_manager_complete_get_thumbnail(manager, invocation, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean manager_delete_object(
@@ -843,9 +914,11 @@ gboolean manager_delete_object(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(manager);
@@ -856,16 +929,19 @@ gboolean manager_delete_object(
 
        if (mtp_daemon_controller_push(__manager_delete_object_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -879,4 +955,5 @@ OUT:
        mtp_gdbuslib_manager_complete_delete_object(manager, invocation, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
index dc945a31a75bd2311d65bcb67f1085aa75ec9bc3..f4876584c2b78e4e13a466703eb696adda5acb7d 100755 (executable)
@@ -48,6 +48,7 @@ static void __objectinfo_get_property_thread_func(gpointer user_data)
                object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
 
                if (object_info != NULL) {
+                       /* LCOV_EXCL_START */
                        switch (property) {
                        case MTP_PROPERTY_ASSOCIATION_DESC:
                                property_value = object_info->AssociationDesc;
@@ -99,14 +100,17 @@ static void __objectinfo_get_property_thread_func(gpointer user_data)
                                break;
                        }
                        MTP_LOGI("property value is %d", property_value);
+                       /* LCOV_EXCL_STOP */
                } else {
                        property_value = -999;
                        MTP_LOGE("object_info is NULL");
                }
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                property_value = -999;
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_objectinfo_complete_get_property(param->object,
@@ -148,6 +152,7 @@ static void __objectinfo_get_property_string_thread_func(gpointer user_data)
                object_info = LIBMTP_Get_Object_Info(mtp_device, object_handle);
 
                if (object_info != NULL) {
+                       /* LCOV_EXCL_START */
                        switch (property) {
                        case MTP_PROPERTY_FILENAME:
                                property_value = object_info->Filename;
@@ -160,14 +165,17 @@ static void __objectinfo_get_property_string_thread_func(gpointer user_data)
                                break;
                        }
                        MTP_LOGI("property_value is %s", property_value);
+                       /* LCOV_EXCL_STOP */
                } else {
                        property_value = NULL;
                        MTP_LOGE("object_info is NULL");
                }
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                property_value = NULL;
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_objectinfo_complete_get_property_string(param->object,
@@ -193,9 +201,11 @@ gboolean objectinfo_get_property(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(objectinfo);
@@ -207,16 +217,19 @@ gboolean objectinfo_get_property(
 
        if (mtp_daemon_controller_push(__objectinfo_get_property_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -228,6 +241,7 @@ OUT:
                invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean objectinfo_get_property_string(
@@ -244,9 +258,11 @@ gboolean objectinfo_get_property_string(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(objectinfo);
@@ -258,16 +274,19 @@ gboolean objectinfo_get_property_string(
 
        if (mtp_daemon_controller_push(__objectinfo_get_property_string_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -279,5 +298,6 @@ OUT:
                invocation, NULL, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
index 3185668969f7e6cd55011061f64f9a9c11148e69..85f753fdcccec82cfc7ab2ad3783542e926f18a0 100755 (executable)
@@ -47,13 +47,15 @@ static void __storageinfo_get_description_thread_func(gpointer user_data)
                        mtp_storage, param->mtp_ctx);
 
                if (storage)
-                       name = storage->StorageDescription;
+                       name = storage->StorageDescription; //LCOV_EXCL_LINE
 
                MTP_LOGI("device_id: %d, mtp_storage: %d, StorageDescription: %s",
                        device_id, mtp_storage, name);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_storageinfo_complete_get_description(param->object,
@@ -93,13 +95,15 @@ static void __storageinfo_get_freespace_thread_func(gpointer user_data)
                        mtp_storage, param->mtp_ctx);
 
                if (storage)
-                       value = storage->FreeSpaceInBytes;
+                       value = storage->FreeSpaceInBytes; //LCOV_EXCL_LINE
 
                MTP_LOGI("device_id: %d, mtp_storage: %d, FreeSpaceInBytes: %llu",
                        device_id, mtp_storage, value);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_storageinfo_complete_get_free_space(param->object,
@@ -138,13 +142,15 @@ static void __storageinfo_get_maxcapacity_thread_func(gpointer user_data)
                        mtp_storage, param->mtp_ctx);
 
                if (storage)
-                       value = storage->MaxCapacity;
+                       value = storage->MaxCapacity; //LCOV_EXCL_LINE
 
                MTP_LOGI("device_id: %d, mtp_storage: %d, MaxCapacity: %llu",
                        device_id, mtp_storage, value);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_storageinfo_complete_get_max_capacity(param->object,
@@ -183,13 +189,15 @@ static void __storageinfo_get_storagetype_thread_func(gpointer user_data)
                        mtp_storage, param->mtp_ctx);
 
                if (storage)
-                       value = storage->StorageType;
+                       value = storage->StorageType; //LCOV_EXCL_LINE
 
                MTP_LOGI("device_id: %d, mtp_storage: %d, StorageType: %d",
                        device_id, mtp_storage, value);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_storageinfo_complete_get_storage_type(param->object,
@@ -228,13 +236,15 @@ static void __storageinfo_get_volumeidentifier_thread_func(gpointer user_data)
                        mtp_storage, param->mtp_ctx);
 
                if (storage)
-                       name = storage->VolumeIdentifier;
+                       name = storage->VolumeIdentifier; //LCOV_EXCL_LINE
 
                MTP_LOGI("device_id: %d, mtp_storage: %d, VolumeIdentifier: %s",
                        device_id, mtp_storage, name);
        } else {
+               /* LCOV_EXCL_START */
                MTP_LOGE("No MTP device");
                result = MTP_ERROR_NO_DEVICE;
+               /* LCOV_EXCL_STOP */
        }
 
        mtp_gdbuslib_storageinfo_complete_get_volume_identifier(param->object,
@@ -257,9 +267,11 @@ gboolean storageinfo_get_description(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(storageinfo);
@@ -270,16 +282,19 @@ gboolean storageinfo_get_description(
 
        if (mtp_daemon_controller_push(__storageinfo_get_description_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -290,6 +305,7 @@ OUT:
        mtp_gdbuslib_storageinfo_complete_get_description(storageinfo, invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean storageinfo_get_freespace(
@@ -304,9 +320,11 @@ gboolean storageinfo_get_freespace(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(storageinfo);
@@ -317,16 +335,19 @@ gboolean storageinfo_get_freespace(
 
        if (mtp_daemon_controller_push(__storageinfo_get_freespace_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -337,6 +358,7 @@ OUT:
        mtp_gdbuslib_storageinfo_complete_get_free_space(storageinfo, invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean storageinfo_get_maxcapacity(
@@ -351,9 +373,11 @@ gboolean storageinfo_get_maxcapacity(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(storageinfo);
@@ -364,16 +388,19 @@ gboolean storageinfo_get_maxcapacity(
 
        if (mtp_daemon_controller_push(__storageinfo_get_maxcapacity_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -384,6 +411,7 @@ OUT:
        mtp_gdbuslib_storageinfo_complete_get_max_capacity(storageinfo, invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean storageinfo_get_storagetype(
@@ -398,9 +426,11 @@ gboolean storageinfo_get_storagetype(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(storageinfo);
@@ -411,16 +441,19 @@ gboolean storageinfo_get_storagetype(
 
        if (mtp_daemon_controller_push(__storageinfo_get_storagetype_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -431,6 +464,7 @@ OUT:
        mtp_gdbuslib_storageinfo_complete_get_storage_type(storageinfo, invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean storageinfo_get_volumeidentifier(
@@ -445,9 +479,11 @@ gboolean storageinfo_get_volumeidentifier(
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
+               /* LCOV_EXCL_START */
                MTP_LOGE("Memory allocation failed");
                result = MTP_ERROR_OUT_OF_MEMORY;
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        param->object = g_object_ref(storageinfo);
@@ -458,16 +494,19 @@ gboolean storageinfo_get_volumeidentifier(
 
        if (mtp_daemon_controller_push(__storageinfo_get_volumeidentifier_thread_func,
                param, param->mtp_ctx) != MTP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                /* return error if queue was blocked */
                MTP_LOGE("controller is processing important message");
                result = MTP_ERROR_CONTROLLER;
 
                goto OUT;
+               /* LCOV_EXCL_STOP */
        }
 
        return TRUE;
 
 OUT:
+       /* LCOV_EXCL_START */
        if (param != NULL) {
                g_object_unref(param->invocation);
                g_object_unref(param->object);
@@ -479,5 +518,6 @@ OUT:
                invocation, 0, result);
 
        return TRUE;
+       /* LCOV_EXCL_STOP */
 }
 
index 84ef545ca0343dd153de7505aa193a385e7dd01b..654d6b97a9c091a2c177dd1d67e42145b63c2f77 100755 (executable)
@@ -29,7 +29,7 @@ LIBMTP_devicestorage_t *mtp_daemon_util_get_storage_handle(
 
                if (device_info != NULL && device_info->device == mtp_device) {
                        for (storage = device_info->device->storage; storage != NULL; storage = storage->next) {
-                               if (storage->id == mtp_storage)
+                               if (storage->id == mtp_storage) //LCOV_EXCL_LINE
                                        return storage;
                        }
                }
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..41a74cf
--- /dev/null
@@ -0,0 +1,33 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-mtp-initiator C CXX)
+
+SET(GTEST_TEST "gtest-mtp-initiator")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+       glib-2.0
+       gio-2.0
+       gmock
+       dlog
+       capi-system-info
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
diff --git a/unittest/common.h b/unittest/common.h
new file mode 100644 (file)
index 0000000..b145592
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+#ifndef __MTP_INITIATOR_CONF_H__
+#define __MTP_INITIATOR_CONF_H__
+
+#include <glib.h>
+
+#ifdef USE_DLOG
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "MTP_INITIATOR_GTEST"
+#define GLOGD(format, args...) LOGD(format, ##args)
+#else
+#define GLOGD(format, args...)
+#endif
+
+#define  MTP_FEATURE "http://tizen.org/feature/network.mtp"
+
+
+typedef enum {
+       ERROR_NONE = 0,
+       ERROR_NOT_PERMITTED = -1,
+       ERROR_OUT_OF_MEMORY = -2,
+       ERROR_PERMISSION_DENIED = -3,
+       ERROR_RESOURCE_BUSY = -4,
+       ERROR_INVALID_OPERATION = -5,
+       ERROR_INVALID_PARAMETER = -6,
+       ERROR_NOT_SUPPORTED = -7,
+       ERROR_OPERATION_FAILED = -8,
+       ERROR_NOT_INITIALIZED = -9,
+       ERROR_ALREADY_INITIALIZED = -10,
+       ERROR_IN_PROGRESS = -11,
+} error_e;
+#endif /* __MTP_INITIATOR_CONF_H__ */
diff --git a/unittest/gdbus.cpp b/unittest/gdbus.cpp
new file mode 100644 (file)
index 0000000..f3919b2
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2018 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 <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "gdbus.h"
+
+GDbus::GDbus()
+{
+       this->m_pConnection = NULL;
+       this->m_pCancellable = NULL;
+}
+
+GDbus::~GDbus()
+{
+       GDBusConnection *conn = this->m_pConnection;
+       GCancellable *cancel = this->m_pCancellable;
+
+       if (cancel) {
+               g_cancellable_cancel(cancel);
+               g_object_unref(cancel);
+               cancel = NULL;
+       }
+
+       if (conn) {
+               g_object_unref(conn);
+               conn = NULL;
+       }
+}
+
+error_e GDbus::Create(void)
+{
+       GError *err = NULL;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+       g_type_init();
+#endif
+
+       this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (this->m_pConnection == NULL) {
+               if (err != NULL) {
+                       GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message);
+                       g_error_free(err);
+               }
+
+               return ERROR_OPERATION_FAILED;
+       }
+
+       this->m_pCancellable = g_cancellable_new();
+
+       return ERROR_NONE;
+}
+
+error_e GDbus::Destroy(void)
+{
+       g_cancellable_cancel(this->m_pCancellable);
+       g_object_unref(this->m_pCancellable);
+       this->m_pCancellable = NULL;
+
+       g_object_unref(this->m_pConnection);
+       this->m_pConnection = NULL;
+
+       return ERROR_NONE;
+}
+
+GDBusConnection *GDbus::GetConnection(void)
+{
+       return this->m_pConnection;
+}
+
+GCancellable *GDbus::GetCancellable(void)
+{
+       return this->m_pCancellable;
+}
+
+error_e GDbus::ConvertErrorStringToEnum(const char *error)
+{
+       if (NULL != strstr(error, "NoReply"))
+               return ERROR_INVALID_OPERATION;
+       else if (NULL != strstr(error, "Failed"))
+               return ERROR_OPERATION_FAILED;
+       else if (NULL != strstr(error, "UnknownMethod"))
+               return ERROR_INVALID_OPERATION;
+       else if (NULL != strstr(error, "InvalidArguments"))
+               return ERROR_INVALID_PARAMETER;
+       else if (NULL != strstr(error, "AccessDenied"))
+               return ERROR_PERMISSION_DENIED;
+       else if (NULL != strstr(error, "PermissionDenied"))
+               return ERROR_PERMISSION_DENIED;
+       else if (NULL != strstr(error, "NotSupported"))
+               return ERROR_NOT_SUPPORTED;
+       else if (NULL != strstr(error, "InProgress"))
+               return ERROR_IN_PROGRESS;
+
+       return ERROR_OPERATION_FAILED;
+}
+
+GVariant *GDbus::InvokeMethod(const char *dest, const char *path,
+               const char *iface_name, const char *method, GVariant *params, error_e *dbus_error)
+{
+       GError *error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection = NULL;
+       *dbus_error = ERROR_NONE;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               *dbus_error = ERROR_NOT_INITIALIZED;
+               return reply;
+       }
+
+       reply = g_dbus_connection_call_sync(connection,
+                       dest,
+                       path,
+                       iface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       DBUS_REPLY_TIMEOUT,
+                       GetCancellable(),
+                       &error);
+
+       if (reply == NULL) {
+               if (error != NULL) {
+                       GLOGD("g_dbus_connection_call_sync() failed "
+                                       "error [%d: %s]", error->code, error->message);
+                       *dbus_error = ConvertErrorStringToEnum(error->message);
+                       g_error_free(error);
+               } else {
+                       GLOGD("g_dbus_connection_call_sync() failed");
+                       *dbus_error = ERROR_OPERATION_FAILED;
+               }
+
+               return NULL;
+       }
+
+       return reply;
+}
diff --git a/unittest/gdbus.h b/unittest/gdbus.h
new file mode 100644 (file)
index 0000000..afc0bc4
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef __MTP_INIATOR_GDBUS_H__
+#define __MTP_INIATOR_GDBUS_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "common.h"
+
+#define GMAINTIMEOUT 10000
+#define DBUS_REPLY_TIMEOUT (120 * 1000)
+
+#define MTP_INITIATOR                  "org.tizen.mtp"
+
+#define MTP_INITIATOR_PATH             "/org/tizen/mtp/manager"
+#define MTP_INITIATOR_INTERFACE                "org.tizen.mtp.manager"
+
+#define MTP_DEVICE_PATH                        "/org/tizen/mtp/deviceinfo"
+#define MTP_DEVICE_INTERFACE           "org.tizen.mtp.deviceinfo"
+
+#define MTP_STORAGE_PATH               "/org/tizen/mtp/storageinfo"
+#define MTP_STORAGE_INTERFACE          "org.tizen.mtp.storageinfo"
+
+#define MTP_OBJECT_PATH                "/org/tizen/mtp/objectinfo"
+#define MTP_OBJECT_INTERFACE           "org.tizen.mtp.objectinfo"
+
+#define GET_DEVICES  "GetDevices"
+#define GET_STORAGES "GetStorages"
+#define GET_OBJECT_HANDLES "GetObjectHandles"
+#define GET_OBJECT "GetObject"
+#define GET_THUMBNAIL "GetThumbnail"
+#define DELETE_OBJECT "DeleteObject"
+#define GET_MANUFACTURER_NAME "GetManufacturerName"
+#define GET_MODEL_NAME "GetModelName"
+#define GET_SERIAL_NAME "GetSerialName"
+#define GET_DEVICE_VERSION "GetDeviceVersion"
+#define GET_STITCHING_ENGINE_VERSION "GetStitchingEngineVersion"
+#define GET_SERIAL_NUMBER "GetSerialNumber"
+#define GET_DESCRIPTION "GetDescription"
+#define GET_PROPERTY "GetProperty"
+#define GET_PROPERTY_VALUE "GetPropertyString"
+#define GET_FREE_SPACE "GetFreeSpace"
+#define GET_MAX_CAPACITY "GetMaxCapacity"
+#define GET_VOLUME_IDENTIFIER "GetVolumeIdentifier"
+#define GET_STORAGE_TYPE "GetStorageType"
+#define GET_BUS_LOCATION "GetBusLocation"
+#define GET_DEVICE_NUMBER "GetDeviceNumber"
+#define GET_PARTIAL_OBJECT "GetPartialObject"
+
+class GDbus {
+       private:
+               GDBusConnection *m_pConnection;
+               GCancellable *m_pCancellable;
+       public:
+               GDbus();
+               ~GDbus();
+               error_e Create(void);
+               error_e Destroy(void);
+               GDBusConnection *GetConnection(void);
+               GCancellable *GetCancellable(void);
+               error_e ConvertErrorStringToEnum(const char *error);
+               GVariant *InvokeMethod(const char *dest, const char *path,
+                               const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+               error_e InvokeMethodNonblock(const char *dest, const char *path,
+                               const char *iface_name, const char *method, GVariant *params, int timeout,
+                               GAsyncReadyCallback notify_func, void *user_data);
+               GVariant *InvokeMethod_with_fd(GUnixFDList *fd_list, const char *dest, const char *path,
+                               const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+};
+#endif /* __MTP_INIATOR_GDBUS_H__ */
diff --git a/unittest/mtp_initiator.cpp b/unittest/mtp_initiator.cpp
new file mode 100644 (file)
index 0000000..503f4a0
--- /dev/null
@@ -0,0 +1,634 @@
+/*
+ * Copyright (c) 2018 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 <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "mtp_initiator.h"
+
+MtpInitiator::MtpInitiator(void)
+{
+       Create();
+}
+
+MtpInitiator::~MtpInitiator(void)
+{
+       Destroy();
+}
+
+error_e MtpInitiator::GetDevices(void)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       GVariant *mtp_devices;
+       gint device_count;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_DEVICES,
+               NULL,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i@aa{sv}i)", &device_count, &mtp_devices,
+                       &result);
+
+       GLOGD("discovered devices[%d], result[%d]", device_count, result);
+
+       g_variant_unref(message);
+       g_variant_unref(mtp_devices);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStorages(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       GVariant *mtp_storages;
+       gint storage_count;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_STORAGES,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i@aa{sv}i)", &storage_count,
+                       &mtp_storages, &result);
+
+       GLOGD("discoverd storages[%d], result[%d]", storage_count, result);
+
+       g_variant_unref(message);
+       g_variant_unref(mtp_storages);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetObjectHandles(gint mtp_device, gint mtp_storage,
+               gint file_type, gint parent_object_handle)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       GVariant *object_handles;
+       gint object_count;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_OBJECT_HANDLES,
+               g_variant_new("(iiii)", mtp_device, mtp_storage, file_type,
+                       parent_object_handle),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i@aa{sv}i)", &object_count,
+                       &object_handles, &result);
+
+       g_variant_unref(message);
+       g_variant_unref(object_handles);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetObject(gint mtp_device, gint object_handle, char *dest_path)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_OBJECT,
+               g_variant_new("(iis)", mtp_device, object_handle, dest_path),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetPartialObject(gint mtp_device, gint object_handle, char *dest_path,
+               gint offset, gint max_bytes)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gint bytes;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_PARTIAL_OBJECT,
+               g_variant_new("(iisii)", mtp_device, object_handle, dest_path,
+                       offset, max_bytes),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ii)", &bytes, &result);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetThumbnail(gint mtp_device, gint object_handle, char *dest_path)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               GET_THUMBNAIL,
+               g_variant_new("(iis)", mtp_device, object_handle, dest_path),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::DeleteObject(gint mtp_device, gint object_handle)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_INITIATOR_PATH,
+               MTP_INITIATOR_INTERFACE,
+               DELETE_OBJECT,
+               g_variant_new("(ii)", mtp_device, object_handle),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetManufacturerName(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *serial = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_MANUFACTURER_NAME,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &serial, &result);
+       GLOGD("Manufacturer Serial : %s", serial);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetModelName(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *model_name = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_MODEL_NAME,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &model_name, &result);
+       GLOGD("Model name: %s", model_name);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetSerialName(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *serial_number = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_SERIAL_NAME,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &serial_number, &result);
+       GLOGD("serial number : %s", serial_number);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDeviceVersion(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *device_version = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_DEVICE_VERSION,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &device_version, &result);
+       GLOGD("Device version: %s", device_version);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetBusLocation(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       int bus_location = 0;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_BUS_LOCATION,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ii)", &bus_location, &result);
+       GLOGD("Bus location: %d", bus_location);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDeviceNumber(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       int device_num = 0;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_DEVICE_NUMBER,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ii)", &device_num, &result);
+       GLOGD("Device number: %d", device_num);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStitchingEngineVersion(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *engine_number = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_STITCHING_ENGINE_VERSION,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &engine_number, &result);
+       GLOGD("Stitching Engine Version: %s", engine_number);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetSerialNumber(gint mtp_device)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *serial = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_DEVICE_PATH,
+               MTP_DEVICE_INTERFACE,
+               GET_SERIAL_NUMBER,
+               g_variant_new("(i)", mtp_device),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &serial, &result);
+       GLOGD("Serial Number: %s", serial);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetDescription(gint mtp_device, gint storage)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *description = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_STORAGE_PATH,
+               MTP_STORAGE_INTERFACE,
+               GET_DESCRIPTION,
+               g_variant_new("(ii)", mtp_device, storage),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &description, &result);
+       GLOGD("Description: %s", description);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetFreeSpace(gint mtp_device, gint storage)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       guint64 free_space;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_STORAGE_PATH,
+               MTP_STORAGE_INTERFACE,
+               GET_FREE_SPACE,
+               g_variant_new("(ii)", mtp_device, storage),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ti)", &free_space, &result);
+       GLOGD("free space: %" G_GUINT64_FORMAT, free_space);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetMaxCapacity(gint mtp_device, gint storage)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       guint64 max_capacity;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_STORAGE_PATH,
+               MTP_STORAGE_INTERFACE,
+               GET_MAX_CAPACITY,
+               g_variant_new("(ii)", mtp_device, storage),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ti)", &max_capacity, &result);
+       GLOGD("max capacity: %" G_GUINT64_FORMAT, max_capacity);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetStorageType(gint mtp_device, gint storage)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gint storage_type;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_STORAGE_PATH,
+               MTP_STORAGE_INTERFACE,
+               GET_STORAGE_TYPE,
+               g_variant_new("(ii)", mtp_device, storage),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ii)", &storage_type, &result);
+       GLOGD("storage type: %d", storage_type);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetVolumeIdentifier(gint mtp_device, gint storage)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *volume_identifier = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_STORAGE_PATH,
+               MTP_STORAGE_INTERFACE,
+               GET_VOLUME_IDENTIFIER,
+               g_variant_new("(ii)", mtp_device, storage),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &volume_identifier, &result);
+       GLOGD("storage type: %s", volume_identifier);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetProperty(gint mtp_device, gint object_handle, gint property)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gint property_value;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_OBJECT_PATH,
+               MTP_OBJECT_INTERFACE,
+               GET_PROPERTY,
+               g_variant_new("(iii)", mtp_device, object_handle, property),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(ii)", &property_value, &result);
+       GLOGD("storage type: %d", property_value);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e MtpInitiator::GetPropertyString(gint mtp_device, gint object_handle, gint property)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       gint result;
+       gchar *property_string = NULL;
+
+       message = InvokeMethod(MTP_INITIATOR,
+               MTP_OBJECT_PATH,
+               MTP_OBJECT_INTERFACE,
+               GET_PROPERTY_VALUE,
+               g_variant_new("(iii)", mtp_device, object_handle, property),
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(si)", &property_string, &result);
+       GLOGD("storage type: %s", property_string);
+
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
diff --git a/unittest/mtp_initiator.h b/unittest/mtp_initiator.h
new file mode 100644 (file)
index 0000000..e607432
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+#ifndef __MTP_INITIATOR_H__
+#define __MTP_INITIATOR_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "gdbus.h"
+
+class MtpInitiator:public GDbus {
+       private:
+       public:
+               MtpInitiator(void);
+               ~MtpInitiator(void);
+               error_e GetDevices(void);
+               error_e GetStorages(gint mtp_device);
+               error_e GetObjectHandles(gint mtp_device, gint mtp_storage,
+                               gint file_type, gint parent_object_handle);
+               error_e GetObject(gint mtp_device, gint object_handle, char *dest_path);
+               error_e GetPartialObject(gint mtp_device, gint object_handle, char *dest_path,
+                               gint offset, gint max_bytes);
+               error_e DeleteObject(gint mtp_device, gint object_handle);
+               error_e GetThumbnail(gint mtp_device, gint object_handle, char *dest_path);
+               error_e GetManufacturerName(gint mtp_device);
+               error_e GetStitchingEngineVersion(gint mtp_device);
+               error_e GetDeviceNumber(gint mtp_device);
+               error_e GetBusLocation(gint mtp_device);
+               error_e GetDeviceVersion(gint mtp_device);
+               error_e GetSerialName(gint mtp_device);
+               error_e GetModelName(gint mtp_device);
+               error_e GetDescription(gint mtp_device, gint storage);
+               error_e GetFreeSpace(gint mtp_device, gint storage);
+               error_e GetMaxCapacity(gint mtp_device, gint storage);
+               error_e GetStorageType(gint mtp_device, gint storage);
+               error_e GetVolumeIdentifier(gint mtp_device, gint storage);
+               error_e GetPropertyString(gint mtp_device, gint object_handle, gint property);
+               error_e GetProperty(gint mtp_device, gint object_handle, gint property);
+               error_e GetSerialNumber(gint mtp_device);
+
+};
+
+#endif /* __MTP_INITIATOR_H__ */
diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp
new file mode 100644 (file)
index 0000000..efb6a40
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2017 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 <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <glib.h>
+#include <system_info.h>
+
+#include "mtp_initiator.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+char *feature_name = (char *)"http://tizen.org/feature/network.mtp";
+
+int CheckFeature()
+{
+       bool mtp_supported = FALSE;
+       if (!system_info_get_platform_bool(feature_name, &mtp_supported)) {
+               if (FALSE == mtp_supported) {
+                       GLOGD("mtp feature is disabled");       // LCOV_EXCL_LINE
+                       return ERROR_NOT_SUPPORTED;
+               }
+               return ERROR_NONE;
+       } else {
+               GLOGD("Error - Feature getting from System Info");      // LCOV_EXCL_LINE
+               return ERROR_INVALID_PARAMETER;
+       }
+}
+
+TEST(MtpManager_t, GetDevices_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetDevices();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetStorages_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetStorages(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetObjectHandles_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetObjectHandles(1, 1, 0, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetObject_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetObject(1, 1, "/tmp/gtest_file");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetPartialObject_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetPartialObject(1, 1, "/tmp/gtest_file", 0, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, GetThumbnail_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetThumbnail(1, 1, "/tmp/gtest_thumb");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpManager_t, DeleteObject_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.DeleteObject(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetManufacturerName_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetManufacturerName(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetModelName_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetModelName(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetDeviceVersion_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetDeviceVersion(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetBusLocation_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetBusLocation(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetDeviceNumber_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetDeviceNumber(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+TEST(MtpDeviceInfo_t, GetStitchingEngineVersion_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetStitchingEngineVersion(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpDeviceInfo_t, GetSerialNumber_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetSerialNumber(1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetDescription_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetDescription(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetFreeSpace_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetFreeSpace(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetMaxCapacity_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetMaxCapacity(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetStorageType_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetStorageType(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpStorageInfo_t, GetVolumeIdentifier_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetVolumeIdentifier(1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpObjectInfo_t, GetProperty_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetProperty(1, 1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(MtpObjectInfo_t, GetPropertyString_p)
+{
+       int ret = 0;
+       MtpInitiator M;
+
+       ret = M.GetPropertyString(1, 1, 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+int main(int argc, char **argv)
+{
+       int ret = 0;
+       ret = CheckFeature();
+
+       if (ERROR_NONE != ret)
+               return ret;
+
+       InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}