Fix memory leak
[platform/core/api/media-content.git] / test / media-content_test.c
index a041de2..1146ffe 100755 (executable)
@@ -917,7 +917,6 @@ int test_filter_create(void)
 
        /* Filter for media */
        const char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
-       /*const char *condition = "MEDIA_TYPE IS NOT 0 AND MEDIA_DESCRIPTION IS NOT NULL"; */   /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
 
        ret = media_filter_create(&g_filter);
 
@@ -1776,6 +1775,12 @@ int test_tag_operation_v2(void)
        return ret;
 }
 
+static void __bookmark_handle_free(gpointer data)
+{
+       media_bookmark_h handle = (media_bookmark_h) data;
+       media_bookmark_destroy(handle);
+}
+
 int test_bookmark_operation(void)
 {
        /* bookmark is only supported for video information. */
@@ -1834,6 +1839,9 @@ int test_bookmark_operation(void)
                        content_error("error media_bookmark_update_to_db : [%d]", ret);
        }
 
+       if (all_item_list)
+               g_list_free_full(all_item_list, __bookmark_handle_free);
+
        ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, NULL);
        if (ret != MEDIA_CONTENT_ERROR_NONE)
                content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
@@ -2421,6 +2429,81 @@ END:
        return ret;
 }
 
+int test_ebook_text_finder(const char *keyword)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       char **book_path_list = NULL;
+       unsigned int book_path_len = 0;
+       unsigned int i = 0;
+       media_info_h media = NULL;
+       book_meta_h book = NULL;
+       char *s_value = NULL;
+       long long ms_time = 0;
+       struct timeval start_time;
+       struct timeval end_time;
+
+       gettimeofday(&start_time, NULL);
+
+       ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
+       if (ret == MEDIA_CONTENT_ERROR_NONE)
+               content_debug("book_meta_get_path_with_keyword is success");
+       else
+               content_error("book_meta_get_path_with_keyword is failed");
+
+       gettimeofday(&end_time, NULL);
+
+       for (i = 0; i < book_path_len; i++) {
+               ret = media_info_get_media_from_db_by_path(book_path_list[i], &media);
+               if (ret != MEDIA_CONTENT_ERROR_NONE)
+                       continue;
+
+               content_debug("===============================");
+               content_debug("[%d] %s", i, book_path_list[i]);
+               content_debug("===============================");
+               media_info_get_title(media, &s_value);
+               content_debug("Title  : %s", s_value);
+               g_free(s_value);
+               s_value = NULL;
+
+               ret = media_info_get_book(media, &book);
+               if (ret != MEDIA_CONTENT_ERROR_NONE) {
+                       media_info_destroy(media);
+                       continue;
+               }
+
+               ret = book_meta_get_author(book, &s_value);
+               if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
+                       content_debug("Author : %s", s_value);
+                       g_free(s_value);
+                       s_value = NULL;
+               }
+
+               ret = book_meta_get_date(book, &s_value);
+               if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
+                       content_debug("Date   : %s", s_value);
+                       g_free(s_value);
+                       s_value = NULL;
+               }
+
+               content_debug("===============================");
+               ret = book_meta_destroy(book);
+               if (ret != MEDIA_CONTENT_ERROR_NONE)
+                       content_error("book_meta_destroy failed");
+
+               ret = media_info_destroy(media);
+               if (ret != MEDIA_CONTENT_ERROR_NONE)
+                       content_error("media_info_destroy failed");
+
+               g_free(book_path_list[i]);
+       }
+
+       ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
+       content_debug("Search Time [%lld]", ms_time);
+
+       g_free(book_path_list);
+
+       return ret;
+}
 int test_disconnect_database(void)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -2750,7 +2833,7 @@ void _noti_cb(media_content_error_e error,
        if (error == 0)
                content_debug("noti success! : %d\n", error);
        else
-               content_debug("error occured! : %d\n", error);
+               content_debug("error occurred! : %d\n", error);
 
        content_debug("Noti from PID(%d)\n", pid);
 
@@ -2801,7 +2884,7 @@ void _noti_cb_2(media_content_error_e error,
        if (error == 0)
                content_debug("noti_2 success! : %d\n", error);
        else
-               content_debug("error occured! : %d\n", error);
+               content_debug("error occurred! : %d\n", error);
 
        content_debug("Noti_2 from PID(%d)\n", pid);
 
@@ -3030,7 +3113,7 @@ int test_tv_filter_create(void)
 
        ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
 
-       ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_STORAGE_ID, MEDIA_CONTENT_COLLATE_DEFAULT);
+       ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
 
        return ret;
 }
@@ -3357,6 +3440,12 @@ int main(int argc, char *argv[])
 #endif
 
 #if 0
+       if (argc == 2) {
+               ret = test_ebook_text_finder(argv[1]);
+               if (ret != MEDIA_CONTENT_ERROR_NONE)
+                       return ret;
+       }
+
        ret = test_start_face_detection(FALSE);
        if (ret != MEDIA_CONTENT_ERROR_NONE)
                return ret;