[UTC][media-content][Non-ACR] media-storage code cleanup 42/266942/2
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 23 Nov 2021 03:37:58 +0000 (12:37 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 23 Nov 2021 04:17:25 +0000 (13:17 +0900)
Change-Id: I68b29b6edfa1f6a7c3aa6af8827929603c29ca21
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/utc/media-content/utc-media-storage.c

index da35a394c2015b8b74770f13e90c95b0b4854ebf..5e838f2e1779f186ac2ef7d13eb36a6c0c1c80f3 100755 (executable)
 //& set: MediaAudio
 
 static media_storage_h g_storage;
-static media_storage_h g_storage_dst;
-static filter_h g_filter;
 static char *g_storage_id = NULL;
+static char *g_val_str = NULL;
+static int g_val_int = 0;
+static int startup_ret = MEDIA_CONTENT_ERROR_NONE;
 
-static media_content_error_e startup_ret = MEDIA_CONTENT_ERROR_NONE;
-
-static bool media_item_cb(media_info_h media, void *user_data)
+static bool __media_item_cb(media_info_h media, void *user_data)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       if (g_storage_id) {
-               free(g_storage_id);
-               g_storage_id = NULL;
-       }
-
-       ret = media_info_get_storage_id(media, &g_storage_id);
-       if ((ret != MEDIA_CONTENT_ERROR_NONE) || (g_storage_id == NULL))
-               return false;
-
-       return true;
+       return false;
 }
 
-static bool _media_storage_cb(media_storage_h storage, void *user_data)
+static bool __media_storage_cb(media_storage_h storage, void *user_data)
 {
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       char *storage_path = NULL;
-       media_content_storage_e storage_type;
-
-       ret = media_storage_clone(&g_storage, storage);
-       if ((ret != MEDIA_CONTENT_ERROR_NONE) || (g_storage == NULL))
-               goto MEDIA_STORAGE_CB_FAIL;
-
-       ret = media_storage_get_id(storage, &g_storage_id);
-       if ((ret != MEDIA_CONTENT_ERROR_NONE) || (g_storage_id == NULL))
-               goto MEDIA_STORAGE_CB_FAIL;
-
-       ret = media_storage_get_path(storage, &storage_path);
-       if ((ret != MEDIA_CONTENT_ERROR_NONE) || (storage_path == NULL))
-               goto MEDIA_STORAGE_CB_FAIL;
-
-       ret = media_storage_get_type(storage, &storage_type);
-       if ((ret != MEDIA_CONTENT_ERROR_NONE))
-               goto MEDIA_STORAGE_CB_FAIL;
-
-       if (storage_path) {
-               free(storage_path);
-               storage_path = NULL;
+       if (media_storage_clone(&g_storage, storage) != MEDIA_CONTENT_ERROR_NONE) {
+               FPRINTF("[Line : %d] media_storage_clone failed.\\n", __LINE__);
+               return false;
        }
 
-       return true;
- MEDIA_STORAGE_CB_FAIL:
-       if (g_storage) {
-               media_storage_destroy(g_storage);
-               g_storage = NULL;
-       }
-       if (g_storage_id) {
-               free(g_storage_id);
-               g_storage_id = NULL;
-       }
-       if (storage_path) {
-               free(storage_path);
-               storage_path = NULL;
+       if (media_storage_get_id(g_storage, &g_storage_id) != MEDIA_CONTENT_ERROR_NONE) {
+               FPRINTF("[Line : %d] media_storage_get_id failed.\\n", __LINE__);
+               return false;
        }
+
        return false;
 }
 
@@ -93,55 +52,15 @@ static bool _media_storage_cb(media_storage_h storage, void *user_data)
  */
 void utc_media_storage_startup(void)
 {
-       media_content_error_e ret = MEDIA_CONTENT_ERROR_NONE;
-
-       g_filter = NULL;
-       g_storage = NULL;
-       g_storage_dst = NULL;
-
-       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;
-       }
-
-       char *condition = "MEDIA_TYPE=3 AND MEDIA_STORAGE_TYPE=0";      //Music
-
-       media_filter_create(&g_filter);
-       media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
-       media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
-       if (g_filter == NULL) {
-               fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
-               fprintf(stderr, "filter is NULL");
-               startup_ret = ret;
-               return;
-       }
-
-       ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
-       if (ret != MEDIA_CONTENT_ERROR_NONE) {
-               fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
-               fprintf(stderr, " media_info_foreach_media_from_db failed (code: %d)\n", ret);
-               startup_ret = ret;
-       }
-
-       if (g_filter != NULL)
-               media_filter_destroy(g_filter);
-
-       media_filter_create(&g_filter);
-       if (g_filter == NULL) {
-               fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
-               fprintf(stderr, "filter is NULL");
-               startup_ret = ret;
+       startup_ret = media_content_connect();
+       if (startup_ret != MEDIA_CONTENT_ERROR_NONE) {
+               FPRINTF("[Line : %d] media_content_connect failed.\\n", __LINE__);
                return;
        }
 
-       ret = media_storage_foreach_storage_from_db(g_filter, _media_storage_cb, NULL);
-       if (ret != MEDIA_CONTENT_ERROR_NONE) {
-               fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
-               fprintf(stderr, " media_storage_foreach_storage_from_db failed (code: %d)\n", ret);
-               startup_ret = ret;
-       }
+       startup_ret = media_storage_foreach_storage_from_db(NULL, __media_storage_cb, NULL);
+       if (startup_ret != MEDIA_CONTENT_ERROR_NONE)
+               FPRINTF("[Line : %d] media_storage_foreach_storage_from_db failed.\\n", __LINE__);
 }
 
 /**
@@ -156,14 +75,9 @@ void utc_media_storage_cleanup(void)
                media_storage_destroy(g_storage);
                g_storage = NULL;
        }
-       if (g_storage_id != NULL) {
-               free(g_storage_id);
-               g_storage_id = NULL;
-       }
-       if (g_filter) {
-               media_filter_destroy(g_filter);
-               g_filter = NULL;
-       }
+
+       FREE_MEMORY(g_storage_id);
+       FREE_MEMORY(g_val_str);
 
        media_content_disconnect();
 }
@@ -177,10 +91,7 @@ int utc_media_storage_get_storage_info_from_db_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_get_storage_info_from_db(g_storage_id, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_get_storage_info_from_db(g_storage_id, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -194,10 +105,10 @@ int utc_media_storage_get_storage_info_from_db_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
+       assert_eq(media_storage_destroy(g_storage), MEDIA_CONTENT_ERROR_NONE);
+       g_storage = NULL;
 
-       ret = media_storage_get_storage_info_from_db(g_storage_id, &g_storage);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_get_storage_info_from_db(g_storage_id, &g_storage), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -211,10 +122,7 @@ int utc_media_storage_get_storage_count_from_db_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_get_storage_count_from_db(g_filter, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_get_storage_count_from_db(NULL, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -228,11 +136,7 @@ int utc_media_storage_get_storage_count_from_db_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       int storage_count = 0;
-
-       ret = media_storage_get_storage_count_from_db(g_filter, &storage_count);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_get_storage_count_from_db(NULL, &g_val_int), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -246,10 +150,7 @@ int utc_media_storage_foreach_storage_from_db_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_foreach_storage_from_db(NULL, NULL, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_foreach_storage_from_db(NULL, NULL, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -263,20 +164,7 @@ int utc_media_storage_foreach_storage_from_db_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       filter_h filter = NULL;
-
-       /* actual test */
-       ret = media_filter_create(&filter);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       ret = media_storage_foreach_storage_from_db(filter, _media_storage_cb, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       if (filter) {
-               media_filter_destroy(filter);
-               filter = NULL;
-       }
+       assert_eq(media_storage_foreach_storage_from_db(NULL, __media_storage_cb, NULL), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -290,10 +178,7 @@ int utc_media_storage_get_media_count_from_db_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_get_media_count_from_db(NULL, g_filter, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_get_media_count_from_db(NULL, NULL, &g_val_int), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -307,11 +192,7 @@ int utc_media_storage_get_media_count_from_db_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       int storage_count = 0;
-
-       ret = media_storage_get_media_count_from_db(g_storage_id, g_filter, &storage_count);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_get_media_count_from_db(g_storage_id, NULL, &g_val_int), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -325,10 +206,7 @@ int utc_media_storage_foreach_media_from_db_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_foreach_media_from_db(NULL, NULL, NULL, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_foreach_media_from_db(NULL, NULL, NULL, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -342,20 +220,7 @@ int utc_media_storage_foreach_media_from_db_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       filter_h filter = NULL;
-
-       /* actual test */
-       ret = media_filter_create(&filter);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       ret = media_storage_foreach_media_from_db(g_storage_id, filter, media_item_cb, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       if (filter) {
-               media_filter_destroy(filter);
-               filter = NULL;
-       }
+       assert_eq(media_storage_foreach_media_from_db(g_storage_id, NULL, __media_item_cb, NULL), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -369,10 +234,7 @@ int utc_media_storage_destroy_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       ret = media_storage_destroy(NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_destroy(NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -386,15 +248,8 @@ int utc_media_storage_destroy_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-
-       /* precondition */
-       ret = media_storage_clone(&g_storage_dst, g_storage);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       /* actual test */
-       ret = media_storage_destroy(g_storage_dst);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_destroy(g_storage), MEDIA_CONTENT_ERROR_NONE);
+       g_storage = NULL;
 
        return 0;
 }
@@ -407,11 +262,11 @@ int utc_media_storage_destroy_p(void)
 int utc_media_storage_clone_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
+       media_storage_h cloned = NULL;
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
+       assert_eq(media_storage_clone(&cloned, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
-       ret = media_storage_clone(&g_storage_dst, NULL);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_clone(NULL, g_storage), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -424,16 +279,11 @@ int utc_media_storage_clone_n(void)
 int utc_media_storage_clone_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
+       media_storage_h cloned = NULL;
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
+       assert_eq(media_storage_clone(&cloned, g_storage), MEDIA_CONTENT_ERROR_NONE);
 
-       ret = media_storage_clone(&g_storage_dst, g_storage);
-
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-       if (g_storage_dst) {
-               ret = media_storage_destroy(g_storage_dst);
-       }
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_destroy(cloned), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -447,16 +297,9 @@ int utc_media_storage_get_id_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       char *storage_id = NULL;
+       assert_eq(media_storage_get_id(NULL, &g_val_str), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
-       ret = media_storage_get_id(NULL, &storage_id);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-
-       if (storage_id) {
-               free(storage_id);
-               storage_id = NULL;
-       }
+       assert_eq(media_storage_get_id(g_storage, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -470,16 +313,7 @@ int utc_media_storage_get_id_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       char *storage_id = NULL;
-
-       ret = media_storage_get_id(g_storage, &storage_id);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
-
-       if (storage_id) {
-               free(storage_id);
-               storage_id = NULL;
-       }
+       assert_eq(media_storage_get_id(g_storage, &g_val_str), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -493,16 +327,9 @@ int utc_media_storage_get_path_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       char *storage_path = NULL;
+       assert_eq(media_storage_get_path(NULL, &g_val_str), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
-       ret = media_storage_get_path(NULL, &storage_path);
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-
-       if (storage_path) {
-               free(storage_path);
-               storage_path = NULL;
-       }
+       assert_eq(media_storage_get_path(g_storage, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -516,17 +343,7 @@ int utc_media_storage_get_path_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       char *storage_path = NULL;
-
-       ret = media_storage_get_path(g_storage, &storage_path);
-
-       if (storage_path) {
-               free(storage_path);
-               storage_path = NULL;
-       }
-
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
+       assert_eq(media_storage_get_path(g_storage, &g_val_str), MEDIA_CONTENT_ERROR_NONE);
 
        return 0;
 }
@@ -539,13 +356,11 @@ int utc_media_storage_get_path_p(void)
 int utc_media_storage_get_type_n(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
-
-       int ret = MEDIA_CONTENT_ERROR_NONE;
        media_content_storage_e storage_type;
 
-       ret = media_storage_get_type(NULL, &storage_type);
+       assert_eq(media_storage_get_type(NULL, &storage_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
-       assert_eq(ret, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+       assert_eq(media_storage_get_type(g_storage, NULL), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
 
        return 0;
 }
@@ -558,12 +373,9 @@ int utc_media_storage_get_type_n(void)
 int utc_media_storage_get_type_p(void)
 {
        assert_eq(startup_ret, MEDIA_CONTENT_ERROR_NONE);
+       media_content_storage_e storage_type = MEDIA_CONTENT_STORAGE_INTERNAL;
 
-       int ret = MEDIA_CONTENT_ERROR_NONE;
-       media_content_storage_e storage_type;
-
-       ret = media_storage_get_type(g_storage, &storage_type);
+       assert_eq(media_storage_get_type(g_storage, &storage_type), MEDIA_CONTENT_ERROR_NONE);
 
-       assert_eq(ret, MEDIA_CONTENT_ERROR_NONE);
        return 0;
 }