Add testcases for GTest 81/166581/1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 11 Jan 2018 02:08:51 +0000 (11:08 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 11 Jan 2018 02:08:51 +0000 (11:08 +0900)
Change-Id: Ifc4b1846adaeca3078eabab01cb9a4175f781e3a
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-share/src/bt-share-common.c
bt-share/src/bt-share-cynara.c
bt-share/src/bt-share-ipc.c
bt-share/src/bt-share-main.c
unittest/CMakeLists.txt
unittest/bluetooth-share_test.cpp

index c48e13b..9096f83 100644 (file)
@@ -66,9 +66,12 @@ int _bt_share_block_sleep(gboolean is_block)
 
        if (is_block) {
                if (block_sleep_count < 0) {
+                       /* This condition is for preventing the exception case, Never be called in the current logic */
+                       /* LCOV_EXCL_START */
                        INFO("block_sleep_count[%d] is invalid. It is set to 0.\n",
                                     block_sleep_count);
                        block_sleep_count = 0;
+                       /* LCOV_EXCL_STOP */
                } else if (block_sleep_count == 0) {
                        result = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
                        if (result != 0)
@@ -132,7 +135,7 @@ int _bt_set_transfer_indicator(gboolean state)
        DBG("event_value: %s", event_val);
 
        if (_bt_set_eventsystem_transfer_value(state) != BT_SHARE_ERROR_NONE)
-               ERR("Fail to set value");
+               ERR("Fail to set value"); /* LCOV_EXCL_LINE */
 
 #if 0
        if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE,
@@ -179,7 +182,7 @@ static char *__bt_share_get_transfer_file_name(int file_type)
 
 void _bt_remove_tmp_file(char *file_path)
 {
-       if (g_str_has_prefix(file_path, BT_TMP_FILE) == TRUE) {
+       if (g_str_has_prefix(file_path, BT_TMP_DIR) == TRUE) {
                DBG_SECURE("Remove the file: %s", file_path);
                ecore_file_remove(file_path);
        }
@@ -221,8 +224,10 @@ char *_bt_share_create_transfer_file(char *text)
        fd = open(file, O_RDWR | O_CREAT, 0755);
 
        if (fd < 0) {
+               /* LCOV_EXCL_START */
                ERR("Fail to open the file : %s", file);
                goto fail;
+               /* LCOV_EXCL_STOP */
        }
 
        if (file_type == BT_HTTP_FILE)
@@ -237,8 +242,10 @@ char *_bt_share_create_transfer_file(char *text)
        close(fd);
 
        if (write_size < 0) {
+               /* LCOV_EXCL_START */
                ERR("Fail to write in file");
                goto fail;
+               /* LCOV_EXCL_STOP */
        }
 
        return file;
index 9683ca7..74da2aa 100644 (file)
@@ -31,6 +31,7 @@
 static cynara *_cynara = NULL;
 const unsigned int error_msg_size = 256;
 
+/* LCOV_EXCL_START */
 // initialize cynara
 int _bt_share_cynara_init(void)
 {
@@ -110,3 +111,4 @@ void _bt_share_cynara_finish(void)
        cynara_finish(_cynara);
        _cynara = NULL;
 }
+/* LCOV_EXCL_STOP */
index 797650e..7526667 100644 (file)
@@ -69,6 +69,7 @@ static void __bt_tr_data_free(bt_tr_data_t *data)
        g_free(data);
 }
 
+/* LCOV_EXCL_START */
 static void __popup_res_cb(int res)
 {
        FN_START;
@@ -96,6 +97,7 @@ static void __popup_res_cb(int res)
        }
        FN_END;
 }
+/* LCOV_EXCL_STOP */
 
 static char *__bt_transfer_folder_path(char *dest_path)
 {
@@ -114,6 +116,7 @@ static char *__bt_transfer_folder_path(char *dest_path)
        return dst_path;
 }
 
+/* LCOV_EXCL_START */
 static opc_transfer_info_t *__add_transfer_info(GVariant *msg)
 {
        FN_START;
@@ -257,6 +260,7 @@ static opc_transfer_info_t *__add_transfer_info(GVariant *msg)
 
        return data;
 }
+/* LCOV_EXCL_STOP */
 
 static void __free_transfer_info(opc_transfer_info_t *node)
 {
@@ -291,6 +295,7 @@ void _remove_transfer_info(opc_transfer_info_t *node)
        FN_END;
 }
 
+/* LCOV_EXCL_START */
 static int __request_file_send(opc_transfer_info_t *node)
 {
        FN_START;
@@ -309,7 +314,9 @@ static int __request_file_send(opc_transfer_info_t *node)
        FN_END;
        return BLUETOOTH_ERROR_NONE;
 }
+/* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
 static void __event_filter(GDBusConnection *connection,
                const gchar *sender_name,
                const gchar *object_path,
@@ -453,6 +460,7 @@ static void __event_filter(GDBusConnection *connection,
                DBG("Unhandled signal");
        }
 }
+/* LCOV_EXCL_STOP */
 
 static int __bt_share_add_filter_subscribe_signal(GDBusConnection *conn,
                gboolean subscribe)
@@ -504,9 +512,11 @@ gboolean _bt_init_dbus_signal(void)
 
        conn = __bt_get_system_gconn();
        if (!conn) {
+               /* LCOV_EXCL_START */
                ERR("GDBUS get failed");
                g_error_free(error);
                return FALSE;
+               /* LCOV_EXCL_STOP */
        }
 
        gdbus_connection = conn;
@@ -628,6 +638,7 @@ static char *__bt_conv_addr_type_to_addr_string(char *addr)
        return g_strdup(address);
 }
 
+/* LCOV_EXCL_START */
 static void __bt_create_send_failed_data(char *filepath, char *dev_name,
                                         char *addr, char *type, unsigned int size)
 {
@@ -658,7 +669,9 @@ static void __bt_create_send_failed_data(char *filepath, char *dev_name,
 
        bt_share_close_db(db);
 }
+/* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
 static void __bt_create_send_data(opc_transfer_info_t *node)
 {
        FN_START;
@@ -707,6 +720,7 @@ static void __bt_create_send_data(opc_transfer_info_t *node)
 
        FN_END;
 }
+/* LCOV_EXCL_STOP */
 
 gboolean _bt_update_sent_data_status(int uid,
                                bt_app_tr_status_e status, char *db_sid)
@@ -823,6 +837,7 @@ int _bt_share_get_unique_id(int db_table, const char *db_sid)
        return index_id;
 }
 
+/* LCOV_EXCL_START */
 static void __bt_share_update_tr_info(int tr_uid, int tr_type)
 {
        DBG("tr_uid = %d", tr_uid);
@@ -916,6 +931,7 @@ static void __bt_share_update_tr_info(int tr_uid, int tr_type)
                bt_share_close_db(db);
        }
 }
+/* LCOV_EXCL_STOP */
 
 static GDBusConnection *__bt_init_system_gconn(void)
 {
index 868ac3d..d9db513 100644 (file)
@@ -48,6 +48,7 @@ static GMainLoop *main_loop = NULL;
 bt_appdata_t *app_state = NULL;
 static guint owner_id;
 
+/* LCOV_EXCL_START */
 static void __lang_changed_cb(keynode_t *node, void *user_data)
 {
        FN_START;
@@ -56,13 +57,14 @@ static void __lang_changed_cb(keynode_t *node, void *user_data)
                        "appcore_set_i18n failed!");
        FN_END;
 }
+/* LCOV_EXCL_STOP */
 
 void _bt_terminate_bluetooth_share(void)
 {
        FN_START;
 
        if (main_loop)
-               g_main_loop_quit(main_loop);
+               g_main_loop_quit(main_loop); /* LCOV_EXCL_LINE */
        else
                terminated = TRUE;
 
@@ -362,6 +364,7 @@ int _bt_init_obex_server(void)
        return BT_SHARE_ERROR_NONE;
 }
 
+/* LCOV_EXCL_START */
 int main(void)
 {
        int ret = 0;
@@ -424,3 +427,4 @@ int main(void)
 
        return BT_SHARE_ERROR_NONE;
 }
+/* LCOV_EXCL_STOP */
index 1f043dc..0b79ec0 100644 (file)
@@ -21,6 +21,9 @@ SET(TARGET_GTEST_TESTS "gtest-bluetooth-share")
 INCLUDE_DIRECTORIES(/usr/include)
 INCLUDE_DIRECTORIES(/usr/include/db-util)
 INCLUDE_DIRECTORIES(/usr/include/glib-2.0)
+INCLUDE_DIRECTORIES(/usr/include/bt-service)
+INCLUDE_DIRECTORIES(/usr/include/notification)
+INCLUDE_DIRECTORIES(/usr/include/appfw)
 INCLUDE_DIRECTORIES(/usr/lib/glib-2.0/include/)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib)
index c8c1b78..99a164a 100644 (file)
@@ -26,6 +26,9 @@
 #include <glib.h>
 #include "bluetooth-share-api.h"
 #include "bt-share-common.h"
+#include "bt-share-ipc.h"
+#include "bt-share-resource.h"
+#include "bt-share-main.h"
 
 using ::testing::EmptyTestEventListener;
 using ::testing::InitGoogleTest;
@@ -42,10 +45,221 @@ TEST(BluetoothShare_test, _bt_share_block_sleep_p) {
        ret = _bt_share_block_sleep(TRUE);
        ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
 
+       ret = _bt_share_block_sleep(TRUE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_share_block_sleep(FALSE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_share_block_sleep(FALSE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+}
+
+TEST(BluetoothShare_test, _bt_share_block_sleep_n) {
+       int ret = BT_SHARE_ERROR_NONE;
+
        ret = _bt_share_block_sleep(FALSE);
+       ASSERT_TRUE(ret == BT_SHARE_FAIL);
+}
+
+TEST(BluetoothShare_test, _bt_set_transfer_indicator_p) {
+       int ret = BT_SHARE_ERROR_NONE;
+
+       ret = _bt_set_transfer_indicator(TRUE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_set_transfer_indicator(TRUE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_set_transfer_indicator(FALSE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+
+       ret = _bt_set_transfer_indicator(FALSE);
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+}
+
+TEST(BluetoothShare_test, _bt_remove_tmp_file_p) {
+       _bt_remove_tmp_file(BT_TMP_FILE);
+}
+
+TEST(BluetoothShare_test, _bt_remove_vcf_file_p) {
+       _bt_remove_vcf_file(BT_CONTACT_SHARE_TMP_DIR"test");
+}
+
+TEST(BluetoothShare_test, _bt_share_create_transfer_file_p) {
+       char *file = NULL;
+
+       file = _bt_share_create_transfer_file("http://www.tizen.org");
+       ASSERT_FALSE(file == NULL);
+
+       _bt_remove_tmp_file(HTML_FILE_NAME);
+       g_free(file);
+
+       file = _bt_share_create_transfer_file("Text test");
+       ASSERT_FALSE(file == NULL);
+
+       _bt_remove_tmp_file(TXT_FILE_FORMAT);
+       g_free(file);
+}
+
+TEST(BluetoothShare_test, _bt_share_create_transfer_file_n) {
+       char *file = NULL;
+
+       file = _bt_share_create_transfer_file(NULL);
+       ASSERT_TRUE(file == NULL);
+}
+
+TEST(BluetoothShare_test, _bt_get_time_of_the_day_p) {
+       char *time = NULL;
+
+       time = _bt_get_time_of_the_day();
+       ASSERT_FALSE(time == NULL);
+
+       g_free(time);
+}
+
+TEST(BluetoothShare_test, _bt_share_get_storage_path_p) {
+       char *path = NULL;
+
+       path = _bt_share_get_storage_path(BT_DEFAULT_MEM_PHONE);
+       ASSERT_FALSE(path == NULL);
+
+       g_free(path);
+
+       path = _bt_share_get_storage_path(BT_DEFAULT_MEM_MMC);
+       ASSERT_FALSE(path == NULL);
+
+       g_free(path);
+}
+
+
+TEST(BluetoothShare_test, _bt_share_get_active_uid_p) {
+       int ret = BT_SHARE_ERROR_NONE;
+       uid_t uid = 0;
+
+       ret = _bt_share_get_active_uid(&uid);
+
+       ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
+}
+
+TEST(BluetoothShare_test, _remove_transfer_info_p) {
+       opc_transfer_info_t *data = NULL;
+
+       data = g_new0(opc_transfer_info_t, 1);
+       data->content = g_new0(char *, 1);
+       data->file_path = g_new0(char *, 1);
+       data->file_cnt = 1;
+       data->type = g_new0(char *, 1);
+       data->size = (unsigned int *)g_new0(unsigned int *, 1);
+
+       _remove_transfer_info(data);
+}
+
+TEST(BluetoothShare_test, _bt_init_dbus_signal_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_init_dbus_signal();
+
+       ASSERT_TRUE(ret == TRUE);
+
+       _bt_deinit_dbus_signal();
+}
+
+
+TEST(BluetoothShare_test, _bt_send_disconnected_signal_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_init_dbus_signal();
+
+       ASSERT_TRUE(ret == TRUE);
+
+       _bt_send_disconnected_signal(BT_SHARE_ENG_SIGNAL_OPP_CLIENT_DISCONNECTED,
+                                                       BLUETOOTH_ERROR_NONE, "BT address", 0);
+
+       _bt_deinit_dbus_signal();
+}
+
+TEST(BluetoothShare_test, _bt_update_transfer_list_view_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_init_dbus_signal();
+
+       ASSERT_TRUE(ret == TRUE);
+
+       _bt_update_transfer_list_view(BT_OUTBOUND_TABLE);
+
+       _bt_deinit_dbus_signal();
+}
+
+
+TEST(BluetoothShare_test, _bt_create_warning_popup_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_init_dbus_signal();
+
+       ASSERT_TRUE(ret == TRUE);
+
+       _bt_create_warning_popup(BLUETOOTH_ERROR_INTERNAL, BT_STR_UNABLE_TO_SEND);
+
+       _bt_deinit_dbus_signal();
+}
+
+TEST(BluetoothShare_test, _bt_update_sent_data_status_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_update_sent_data_status(1, BT_TR_ONGOING, "1");
+
+       ASSERT_TRUE(ret == TRUE);
+}
+
+TEST(BluetoothShare_test, _bt_update_recv_data_status_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_update_recv_data_status(1, BT_TR_FAIL, "1", 100, "text/vcard");
+
+       ASSERT_TRUE(ret == TRUE);
+}
+
+TEST(BluetoothShare_test, _bt_update_multiple_sent_data_status_p) {
+       gboolean ret = FALSE;
+
+       int uids[2] = { 1, 2};
+
+       ret = _bt_update_multiple_sent_data_status(uids, 1, BT_TR_FAIL, "1");
+
+       ASSERT_TRUE(ret == TRUE);
+}
+
+TEST(BluetoothShare_test, _bt_add_recv_transfer_status_data_p) {
+       gboolean ret = FALSE;
+
+       ret = _bt_add_recv_transfer_status_data("NAME",
+                                       "ADDRESS", "FILE NAME", NULL,
+                                       100, BT_TR_ONGOING, "1");
+
+       ASSERT_TRUE(ret == TRUE);
+}
+
+TEST(BluetoothShare_test, _bt_share_get_unique_id_p) {
+       int id;
+
+       id = _bt_share_get_unique_id(BT_DB_INBOUND,     "1");
+
+       ASSERT_FALSE(id < 0);
+}
+
+TEST(BluetoothShare_test, _bt_set_eventsystem_transfer_value_p) {
+       int ret = BT_SHARE_ERROR_NONE;
+
+       ret = _bt_set_eventsystem_transfer_value(TRUE);
+
        ASSERT_TRUE(ret == BT_SHARE_ERROR_NONE);
 }
 
+TEST(BluetoothShare_test, _bt_terminate_bluetooth_share_p) {
+       _bt_terminate_bluetooth_share();
+}
+
 int main(int argc, char **argv) {
   InitGoogleTest(&argc, argv);