From: Minje Ahn Date: Wed, 6 Apr 2022 06:21:59 +0000 (+0900) Subject: [UTC][media-content][Non-ACR] media-content refactoring X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ca3208943f4d801c57c10f01a522542616c8a93;p=test%2Ftct%2Fnative%2Fapi.git [UTC][media-content][Non-ACR] media-content refactoring Change-Id: I611f3050d63199c496ab3170efe5a30dea263220 Signed-off-by: Minje Ahn --- diff --git a/src/utc/media-content/utc-media-content.c b/src/utc/media-content/utc-media-content.c index 81ac100ee..760cca009 100755 --- a/src/utc/media-content/utc-media-content.c +++ b/src/utc/media-content/utc-media-content.c @@ -21,48 +21,15 @@ //& set: MediaContent static GMainLoop *g_loop = NULL; -static const char *g_insert_file = "test.jpg"; -static const char *g_origin_file = "image.jpg"; -static char *g_insert_path = NULL; -static char *g_origin_path = NULL; -static char *dir_path = NULL; - -static media_content_error_e cb_result = MEDIA_CONTENT_ERROR_NONE; -static media_content_error_e startup_ret = MEDIA_CONTENT_ERROR_NONE; - -static bool __storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data) -{ - if (type == STORAGE_TYPE_INTERNAL) { - g_origin_path = (char *)malloc(strlen(path) + strlen(g_origin_file) + 6); - memset(g_origin_path, 0x00, strlen(path) + strlen(g_origin_file) + 6); - snprintf(g_origin_path, strlen(path) + strlen(g_origin_file) + 6, "%s/res/%s", path, g_origin_file); - - g_insert_path = (char *)malloc(strlen(path) + strlen(g_insert_file) + 6); - memset(g_insert_path, 0x00, strlen(path) + strlen(g_insert_file) + 6); - snprintf(g_insert_path, strlen(path) + strlen(g_insert_file) + 6, "%s/res/%s", path, g_insert_file); - - dir_path = strdup(path); - - return false; - } - return true; -} +static char *g_file_path = NULL; +static char *g_dir_path = NULL; +static int cb_result = MEDIA_CONTENT_ERROR_NONE; static void _scan_folder_cb(media_content_error_e error, void *user_data) { cb_result = error; -} - -static gboolean _startup_scan_start(gpointer data) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - ret = media_content_scan_folder(dir_path, TRUE, _scan_folder_cb, NULL); - if (ret < 1) { - g_main_loop_quit(g_loop); - cb_result = ret; - } - return false; + g_main_loop_quit(g_loop); } /** @@ -73,49 +40,13 @@ static gboolean _startup_scan_start(gpointer data) */ void utc_media_content_startup(void) { - media_content_error_e ret = MEDIA_CONTENT_ERROR_NONE; - GSource *source = NULL; - GMainContext *context = NULL; - - if (storage_foreach_device_supported(__storage_device_supported_cb, NULL) != STORAGE_ERROR_NONE) - fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); - - ret = media_content_connect(); - if (ret != MEDIA_CONTENT_ERROR_NONE) { - fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); - fprintf(stderr, " media_content_connect failed (code: %d)\n", ret); - startup_ret = ret; - return; - } + if (storage_get_root_directory(0, &g_dir_path) == STORAGE_ERROR_NONE) + g_file_path = g_strdup_printf("%s/res/image.jpg", g_dir_path); - g_loop = g_main_loop_new(NULL, FALSE); - context = g_main_loop_get_context(g_loop); - source = g_idle_source_new(); - g_source_set_callback(source, _startup_scan_start, NULL, NULL); - g_source_attach(source, context); - - g_main_loop_run(g_loop); - g_main_loop_unref(g_loop); - - g_loop = NULL; - if (cb_result != MEDIA_CONTENT_ERROR_NONE) { - fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); - fprintf(stderr, " media_content_connect failed (code: %d)\n", ret); - startup_ret = cb_result; + if (media_content_connect() != MEDIA_CONTENT_ERROR_NONE) { + FPRINTF("[Line : %d] media_content_connect failed.\\n", __LINE__); return; } - - if (!g_file_test(g_insert_path, G_FILE_TEST_EXISTS)) { - char test_copy[256] = { 0, }; - snprintf(test_copy, sizeof(test_copy), "/bin/cp %s %s", g_origin_path, g_insert_path); - - if (system(test_copy) < 0) { - fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); - fprintf(stderr, "\"%s\" failed (code: %d)\n", test_copy, ret); - startup_ret = -1; - return; - } - } } /** @@ -126,20 +57,11 @@ void utc_media_content_startup(void) */ void utc_media_content_cleanup(void) { - if (g_insert_path != NULL) { - free(g_insert_path); - g_insert_path = NULL; - } - if (g_origin_path != NULL) { - free(g_origin_path); - g_origin_path = NULL; - } - if (dir_path != NULL) { - free(dir_path); - dir_path = NULL; - } - g_loop = NULL; + FREE_MEMORY(g_file_path); + FREE_MEMORY(g_dir_path); + media_content_disconnect(); + g_loop = NULL; } static void _noti_cb(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item, media_content_db_update_type_e update_type, media_content_type_e media_type, char *uuid, char *path, char *mime_type, void *user_data) @@ -153,12 +75,9 @@ static void _noti_cb(media_content_error_e error, int pid, media_content_db_upda */ int utc_media_content_connect_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_disconnect(), MEDIA_CONTENT_ERROR_NONE); - int ret = MEDIA_CONTENT_ERROR_NONE; - ret = media_content_disconnect(); - ret = media_content_connect(); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_connect(), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -170,13 +89,9 @@ int utc_media_content_connect_p(void) */ int utc_media_content_connect_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_disconnect(), MEDIA_CONTENT_ERROR_NONE); - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_disconnect(); - ret = media_content_connect(); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_connect(), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -188,13 +103,9 @@ int utc_media_content_connect_n(void) */ int utc_media_content_disconnect_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; + assert_eq(media_content_disconnect(), MEDIA_CONTENT_ERROR_NONE); - ret = media_content_disconnect(); - ret = media_content_connect(); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_connect(), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -206,13 +117,9 @@ int utc_media_content_disconnect_p(void) */ int utc_media_content_disconnect_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_disconnect(), MEDIA_CONTENT_ERROR_NONE); - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_disconnect(); - ret = media_content_connect(); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_connect(), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -224,12 +131,7 @@ int utc_media_content_disconnect_n(void) */ int utc_media_content_scan_file_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_scan_file(NULL); - assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + assert_eq(media_content_scan_file(NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return 0; } @@ -241,13 +143,7 @@ int utc_media_content_scan_file_n(void) */ int utc_media_content_scan_file_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_scan_file(g_insert_path); - - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_scan_file(g_file_path), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -259,27 +155,20 @@ int utc_media_content_scan_file_p(void) */ int utc_media_content_scan_folder_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_scan_folder(NULL, FALSE, _scan_folder_cb, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_scan_folder(NULL, FALSE, NULL, NULL); - assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + assert_eq(media_content_scan_folder(g_dir_path, FALSE, NULL, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return 0; } -static gboolean _scan_folder_start(gpointer data) +static gboolean _scan_folder_start_cb(gpointer data) { - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_scan_folder(dir_path, FALSE, _scan_folder_cb, NULL); - - if (ret < 1) { + cb_result = media_content_scan_folder(g_dir_path, FALSE, _scan_folder_cb, NULL); + if (cb_result != MEDIA_CONTENT_ERROR_NONE) g_main_loop_quit(g_loop); - cb_result = ret; - } - return false; + + return G_SOURCE_REMOVE; } /** @@ -289,28 +178,14 @@ static gboolean _scan_folder_start(gpointer data) */ int utc_media_content_scan_folder_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; - - GSource *source = NULL; - GMainContext *context = NULL; - g_loop = g_main_loop_new(NULL, FALSE); - context = g_main_loop_get_context(g_loop); - source = g_idle_source_new(); - g_source_set_callback(source, _scan_folder_start, NULL, NULL); - g_source_attach(source, context); - + g_idle_add(_scan_folder_start_cb, NULL); g_main_loop_run(g_loop); g_main_loop_unref(g_loop); - g_loop = NULL; assert_eq(cb_result, MEDIA_CONTENT_ERROR_NONE); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); - return 0; } @@ -321,12 +196,7 @@ int utc_media_content_scan_folder_p(void) */ int utc_media_content_cancel_scan_folder_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_cancel_scan_folder(NULL); - assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + assert_eq(media_content_cancel_scan_folder(NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return 0; } @@ -338,12 +208,9 @@ int utc_media_content_cancel_scan_folder_n(void) */ int utc_media_content_cancel_scan_folder_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; + assert_eq(media_content_scan_folder(g_dir_path, FALSE, _scan_folder_cb, NULL), MEDIA_CONTENT_ERROR_NONE); - ret = media_content_cancel_scan_folder(dir_path); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_cancel_scan_folder(g_dir_path), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -355,13 +222,11 @@ int utc_media_content_cancel_scan_folder_p(void) */ int utc_media_content_add_db_updated_cb_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; media_content_noti_h noti = NULL; - ret = media_content_add_db_updated_cb(NULL, NULL, ¬i); - assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + assert_eq(media_content_add_db_updated_cb(NULL, NULL, ¬i), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + + assert_eq(media_content_add_db_updated_cb(_noti_cb, NULL, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); noti = NULL; return 0; @@ -374,17 +239,11 @@ int utc_media_content_add_db_updated_cb_n(void) */ int utc_media_content_add_db_updated_cb_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; media_content_noti_h noti = NULL; - ret = media_content_add_db_updated_cb(_noti_cb, NULL, ¬i); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_add_db_updated_cb(_noti_cb, NULL, ¬i), MEDIA_CONTENT_ERROR_NONE); - ret = media_content_remove_db_updated_cb(noti); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); - noti = NULL; + assert_eq(media_content_remove_db_updated_cb(noti), MEDIA_CONTENT_ERROR_NONE); return 0; } @@ -396,11 +255,7 @@ int utc_media_content_add_db_updated_cb_p(void) */ int utc_media_content_remove_db_updated_cb_n(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - int ret = MEDIA_CONTENT_ERROR_NONE; - - ret = media_content_remove_db_updated_cb(NULL); - assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + assert_eq(media_content_remove_db_updated_cb(NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER); return 0; } @@ -412,17 +267,11 @@ int utc_media_content_remove_db_updated_cb_n(void) */ int utc_media_content_remove_db_updated_cb_p(void) { - assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE); - - int ret = MEDIA_CONTENT_ERROR_NONE; media_content_noti_h noti = NULL; - ret = media_content_add_db_updated_cb(_noti_cb, NULL, ¬i); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); + assert_eq(media_content_add_db_updated_cb(_noti_cb, NULL, ¬i), MEDIA_CONTENT_ERROR_NONE); - ret = media_content_remove_db_updated_cb(noti); - assert_eq(ret, MEDIA_CONTENT_ERROR_NONE); - noti = NULL; + assert_eq(media_content_remove_db_updated_cb(noti), MEDIA_CONTENT_ERROR_NONE); return 0; }