2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <media_content.h>
22 #include <media_info_private.h>
26 #include <tzplatform_config.h>
27 #include <media_content_internal.h>
30 static filter_h g_filter = NULL;
31 static filter_h g_filter_g = NULL; /*filter for group like folder, tag, playlist, album, year ... */
33 static GMainLoop *g_loop = NULL;
35 static int g_media_cnt = 0;
37 #define test_audio_id "3304285f-1070-41af-8b4e-f0086cc768f3"
38 #define test_video_id "53c43e7e-53d2-4194-80a6-55d5dcde0def"
39 #define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197"
41 static void get_audio_meta(media_info_h media)
43 audio_meta_h audio = NULL;
47 content_debug("=== audio meta ===");
48 if (media_info_get_audio(media, &audio) != MEDIA_CONTENT_ERROR_NONE)
51 if (audio_meta_get_media_id(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
52 content_debug("audio_id : [%s]", c_value);
56 if (audio_meta_get_album(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
57 content_debug("album : [%s]", c_value);
61 if (audio_meta_get_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
62 content_debug("artist : [%s]", c_value);
66 if (audio_meta_get_album_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
67 content_debug("album artist : [%s]", c_value);
71 if (audio_meta_get_genre(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
72 content_debug("genre : [%s]", c_value);
76 if (audio_meta_get_composer(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
77 content_debug("composer : [%s]", c_value);
81 if (audio_meta_get_year(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
82 content_debug("year : [%s]", c_value);
86 if (audio_meta_get_recorded_date(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
87 content_debug("recorded date : [%s]", c_value);
91 if (audio_meta_get_copyright(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
92 content_debug("copyright : [%s]", c_value);
96 if (audio_meta_get_track_num(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
97 content_debug("track number : [%s]", c_value);
101 if (audio_meta_get_bit_rate(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
102 content_debug("bitrate : [%d]", i_value);
104 if (audio_meta_get_sample_rate(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
105 content_debug("samplerate : [%d]", i_value);
107 if (audio_meta_get_channel(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
108 content_debug("channel : [%d]", i_value);
110 if (audio_meta_get_duration(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
111 content_debug("duration : [%d]", i_value);
113 audio_meta_destroy(audio);
116 static void get_video_meta(media_info_h media)
118 video_meta_h video = NULL;
119 char *c_value = NULL;
122 content_debug("=== video meta ===");
123 if (media_info_get_video(media, &video) != MEDIA_CONTENT_ERROR_NONE)
126 if (video_meta_get_media_id(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
127 content_debug("video_id : [%s]", c_value);
131 if (video_meta_get_album(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
132 content_debug("album : [%s]", c_value);
136 if (video_meta_get_artist(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
137 content_debug("artist : [%s]", c_value);
141 if (video_meta_get_album_artist(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
142 content_debug("album artist : [%s]", c_value);
146 if (video_meta_get_genre(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
147 content_debug("genre : [%s]", c_value);
151 if (video_meta_get_composer(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
152 content_debug("composer : [%s]", c_value);
156 if (video_meta_get_year(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
157 content_debug("year : [%s]", c_value);
161 if (video_meta_get_recorded_date(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
162 content_debug("recorded date : [%s]", c_value);
166 if (video_meta_get_copyright(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
167 content_debug("copyright : [%s]", c_value);
171 if (video_meta_get_track_num(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
172 content_debug("track num : [%s]", c_value);
176 if (video_meta_get_bit_rate(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
177 content_debug("bitrate : [%d]", i_value);
179 if (video_meta_get_duration(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
180 content_debug("duration : [%d]", i_value);
182 if (video_meta_get_width(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
183 content_debug("width : [%d]", i_value);
185 if (video_meta_get_height(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
186 content_debug("height : [%d]", i_value);
188 video_meta_destroy(video);
191 static void get_image_meta(media_info_h media)
193 image_meta_h image = NULL;
194 char *c_value = NULL;
196 media_content_orientation_e orientation;
198 content_debug("=== image meta ===");
199 if (media_info_get_image(media, &image) != MEDIA_CONTENT_ERROR_NONE)
202 if (image_meta_get_width(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
203 content_debug("width : [%d]", i_value);
205 if (image_meta_get_height(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
206 content_debug("height : [%d]", i_value);
208 if (image_meta_get_orientation(image, &orientation) == MEDIA_CONTENT_ERROR_NONE)
209 content_debug("orientation : [%d]", orientation);
211 if (image_meta_get_date_taken(image, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
212 content_debug("datetaken : [%s]", c_value);
216 image_meta_destroy(image);
219 static void get_book_meta(media_info_h media)
221 book_meta_h book = NULL;
222 char *c_value = NULL;
224 content_debug("=== book meta ===");
225 if (media_info_get_book(media, &book) != MEDIA_CONTENT_ERROR_NONE)
228 if (book_meta_get_media_id(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
229 content_debug("media_id : [%s]", c_value);
233 if (book_meta_get_author(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
234 content_debug("author : [%s]", c_value);
238 if (book_meta_get_date(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
239 content_debug("date : [%s]", c_value);
243 if (book_meta_get_publisher(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
244 content_debug("publisher : [%s]", c_value);
248 if (book_meta_get_subject(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
249 content_debug("subject : [%s]", c_value);
253 book_meta_destroy(book);
256 static void get_album_meta(media_album_h album)
258 char *c_value = NULL;
261 content_debug("=== album meta ===");
262 if (media_album_get_album_id(album, &i_value) == MEDIA_CONTENT_ERROR_NONE)
263 content_debug("album id : [%d]", i_value);
265 if (media_album_get_name(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
266 content_debug("album name : [%s]", c_value);
270 if (media_album_get_artist(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
271 content_debug("album artist : [%s]", c_value);
276 static void get_bookmark_meta(media_bookmark_h bookmark)
278 char *c_value = NULL;
282 content_debug("=== bookmark meta ===");
283 if (media_bookmark_get_bookmark_id(bookmark, &i_value) == MEDIA_CONTENT_ERROR_NONE)
284 content_debug("bookmark_id : %d", i_value);
286 if (media_bookmark_get_thumbnail_path(bookmark, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
287 content_debug("bookmark thumbnail_path : %s", c_value);
291 if (media_bookmark_get_marked_time(bookmark, &time) == MEDIA_CONTENT_ERROR_NONE)
292 content_debug("bookmark marked_time : %ld", time);
294 if (media_bookmark_get_name(bookmark, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
295 content_debug("bookmark name : %s", c_value);
300 static void get_tag_meta(media_tag_h tag)
302 char *c_value = NULL;
305 content_debug("=== tag meta ===");
306 if (media_tag_get_tag_id(tag, &i_value) == MEDIA_CONTENT_ERROR_NONE)
307 content_debug("tag_id : %d", i_value);
309 if (media_tag_get_name(tag, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
310 content_debug("tag_name : %s", c_value);
315 static void get_face_meta(media_face_h face)
317 char *c_value = NULL;
318 unsigned int rect_x = 0;
319 unsigned int rect_y = 0;
320 unsigned int rect_w = 0;
321 unsigned int rect_h = 0;
322 media_content_orientation_e orientation = 0;
324 content_debug("=== face meta ===");
325 if (media_face_get_face_id(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
326 content_debug("face_id : %s", c_value);
330 if (media_face_get_media_id(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
331 content_debug("media_id : %s", c_value);
335 if (media_face_get_face_rect(face, &rect_x, &rect_y, &rect_w, &rect_h) == MEDIA_CONTENT_ERROR_NONE)
336 content_debug("face_rect x[%d] y[%d] w[%d] h[%d]", rect_x, rect_y, rect_w, rect_h);
338 if (media_face_get_orientation(face, &orientation) == MEDIA_CONTENT_ERROR_NONE)
339 content_debug("orientation : %d", orientation);
341 if (media_face_get_tag(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
342 content_debug("tag : %s", c_value);
347 static void get_folder_meta(media_folder_h folder, char **folder_id)
349 char *c_value = NULL;
350 media_content_storage_e storage_type;
352 content_debug("=== folder meta ===");
353 if (media_folder_get_folder_id(folder, &c_value) != MEDIA_CONTENT_ERROR_NONE) {
354 content_debug("folder_id : %s", c_value);
355 *folder_id = c_value;
358 if (media_folder_get_path(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
359 content_debug("folder_path : %s", c_value);
363 if (media_folder_get_name(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
364 content_debug("folder_name : %s", c_value);
368 if (media_folder_get_storage_type(folder, &storage_type) == MEDIA_CONTENT_ERROR_NONE)
369 content_debug("storage_type : [%d]", storage_type);
371 if (media_folder_get_storage_id(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
372 content_debug("storage_id : %s", c_value);
377 static void get_media_meta(media_info_h media)
379 char *c_value = NULL;
382 bool b_value = false;
383 unsigned long long size = 0;
384 media_content_type_e media_type = 0;
386 content_debug("=== media meta ===");
387 if (media_info_get_media_type(media, &media_type) == MEDIA_CONTENT_ERROR_NONE)
388 content_debug("media_type : [%d]", media_type);
390 if (media_info_get_media_id(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
391 content_debug("media_id : [%s]", c_value);
395 if (media_info_get_file_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
396 content_debug("file_path : [%s]", c_value);
400 if (media_info_get_display_name(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
401 content_debug("display_name : [%s]", c_value);
405 if (media_info_get_mime_type(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
406 content_debug("mime_type : [%s]", c_value);
410 if (media_info_get_thumbnail_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
411 content_debug("thumbnail_path : [%s]", c_value);
415 if (media_info_get_description(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
416 content_debug("description : [%s]", c_value);
420 if (media_info_get_size(media, &size) == MEDIA_CONTENT_ERROR_NONE)
421 content_debug("size : [%lld]", size);
423 if (media_info_get_added_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
424 content_debug("added_time : [%ld]", t_value);
426 if (media_info_get_modified_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
427 content_debug("modified_time : [%ld]", t_value);
429 if (media_info_get_timeline(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
430 content_debug("timeline : [%ld]", t_value);
432 if (media_info_get_rating(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
433 content_debug("rating : [%d]", i_value);
435 if (media_info_get_favorite(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
436 content_debug("favorite : [%d]", b_value);
438 if (media_info_is_drm(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
439 content_debug("is_drm : [%d]", b_value);
441 if (media_info_is_360_content(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
442 content_debug("is_360 : [%d]", b_value);
444 #ifdef _USE_TVPD_MODE
445 if (media_info_get_stitched_state(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
446 content_debug("360 stitched : [%d]", i_value);
448 if (media_info_get_stitched_engine(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
449 content_debug("360 engine : [%d]", i_value);
452 if (media_type == MEDIA_CONTENT_TYPE_MUSIC)
453 get_audio_meta(media);
455 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
456 get_image_meta(media);
458 if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
459 get_video_meta(media);
461 if (media_type == MEDIA_CONTENT_TYPE_BOOK)
462 get_book_meta(media);
464 if (media_type == MEDIA_CONTENT_TYPE_OTHERS)
465 content_debug("Other type");
468 bool media_item_cb(media_info_h media, void *user_data)
471 content_debug("NO Item");
475 get_media_meta(media);
480 bool gallery_folder_list_cb(media_folder_h folder, void *user_data)
482 media_folder_h new_folder = NULL;
483 media_folder_clone(&new_folder, folder);
485 GList **list = (GList**)user_data;
486 *list = g_list_append(*list, new_folder);
491 bool gallery_media_item_cb(media_info_h media, void *user_data)
493 media_info_h new_media = NULL;
494 int ret = MEDIA_CONTENT_ERROR_NONE;
496 ret = media_info_clone(&new_media, media);
498 if (ret != MEDIA_CONTENT_ERROR_NONE) {
499 GList **list = (GList**)user_data;
500 *list = g_list_append(*list, new_media);
506 bool gallery_tag_item_cb(media_tag_h tag, void *user_data)
508 media_tag_h new_tag = NULL;
509 media_tag_clone(&new_tag, tag);
511 GList **list = (GList**)user_data;
512 *list = g_list_append(*list, new_tag);
517 bool gallery_bookmarks_cb(media_bookmark_h bookmark, void *user_data)
519 media_bookmark_h new_bm = NULL;
520 int ret = MEDIA_CONTENT_ERROR_NONE;
522 ret = media_bookmark_clone(&new_bm, bookmark);
523 if (ret != MEDIA_CONTENT_ERROR_NONE)
524 content_error("error media_bookmark_clone : [%d]", ret);
526 GList **list = (GList**)user_data;
527 *list = g_list_append(*list, new_bm);
532 bool folder_list_cb(media_folder_h folder, void *user_data)
535 char *folder_id = NULL;
536 media_folder_h *_folder = (media_folder_h*)user_data;
538 content_debug("===========================");
539 if (folder != NULL) {
541 media_folder_clone(_folder, folder);
543 get_folder_meta(folder, &folder_id);
545 if (media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) {
546 SAFE_FREE(folder_id);
547 content_error("[ERROR] media_folder_get_media_count_from_db is failed");
551 if (media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) {
552 SAFE_FREE(folder_id);
553 content_error("[ERROR] media_folder_foreach_media_from_db is failed");
557 SAFE_FREE(folder_id);
565 bool playlist_list_cb(media_playlist_h playlist, void *user_data)
567 int ret = MEDIA_CONTENT_ERROR_NONE;
569 char *playlist_name = NULL;
570 media_playlist_h playlist_h;
571 char *playlist_thumbnail_path = NULL;
573 content_debug("playlist_list_cb ======");
575 GList **list = (GList**)user_data;
578 if (playlist == NULL) {
579 content_debug(" playlist handle is NULL");
583 ret = media_playlist_get_playlist_id(playlist, &playlist_id);
584 if (ret != MEDIA_CONTENT_ERROR_NONE)
585 content_error("error media_playlist_get_playlist_id : [%d]", ret);
587 content_debug("playlist_id : %d", playlist_id);
588 /* 64bit build issue */
590 if (user_data != NULL)
591 *list = g_list_append(*list, (gpointer)playlist_id);
593 ret = media_playlist_get_name(playlist, &playlist_name);
594 if (ret != MEDIA_CONTENT_ERROR_NONE)
595 content_error("error media_playlist_get_name : [%d]", ret);
597 content_debug("playlist_name : %s", playlist_name);
598 SAFE_FREE(playlist_name);
600 ret = media_playlist_get_thumbnail_path(playlist, &playlist_thumbnail_path);
601 if (ret != MEDIA_CONTENT_ERROR_NONE)
602 content_error("error media_playlist_get_thumbnail_path : [%d]", ret);
604 content_debug("playlist_thumbnail_path : %s", playlist_thumbnail_path);
605 SAFE_FREE(playlist_thumbnail_path);
607 ret = media_playlist_get_playlist_from_db(playlist_id, &playlist_h);
608 if (ret != MEDIA_CONTENT_ERROR_NONE)
609 content_error("error media_playlist_get_playlist_from_db : [%d]", ret);
611 ret = media_playlist_destroy(playlist_h);
612 if (ret != MEDIA_CONTENT_ERROR_NONE)
613 content_error("error media_playlist_destroy : [%d]", ret);
618 bool tag_list_cb(media_tag_h tag, void *user_data)
621 content_debug(" tag handle is NULL");
630 bool bookmarks_cb(media_bookmark_h bookmark, void *user_data)
632 if (bookmark != NULL && user_data != NULL) {
633 media_bookmark_h new_bookmark;
635 media_bookmark_clone(&new_bookmark, bookmark);
636 GList **list = (GList**)user_data;
637 *list = g_list_append(*list, new_bookmark);
640 get_bookmark_meta(bookmark);
645 bool album_list_cb(media_album_h album, void *user_data)
649 int ret = MEDIA_CONTENT_ERROR_NONE;
652 get_album_meta(album);
653 media_album_get_album_id(album, &album_id);
655 ret = media_album_get_media_count_from_db(album_id, NULL, &media_count);
656 if (ret != MEDIA_CONTENT_ERROR_NONE)
657 content_error("error media_album_get_media_count_from_db : [%d]", ret);
659 content_debug("media_count : [%d]", media_count);
661 ret = media_album_foreach_media_from_db(album_id, NULL, media_item_cb, NULL);
662 if (ret != MEDIA_CONTENT_ERROR_NONE) {
663 content_error("error media_album_foreach_media_from_db : [%d]", ret);
668 content_error("album item not Found!!");
674 bool group_list_cb(const char *group_name, void *user_data)
677 int *idx = user_data;
679 content_debug("group item : [%s] [%d]", group_name, *idx);
681 if (media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
684 content_debug("media_count : [%d]", media_count);
686 if (media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
692 bool playlist_item_cb(int playlist_member_id, media_info_h media, void *user_data)
694 content_debug("playlist_member_id : [%d]", playlist_member_id);
695 /* 64bit build issue */
697 GList **list = (GList**)user_data;
699 *list = g_list_append(*list, (gpointer)playlist_member_id);
701 /*media_item_cb(media, user_data);*/
706 int test_filter_create(void)
708 content_debug("\n============Filter Create============\n\n");
710 int ret = MEDIA_CONTENT_ERROR_NONE;
712 /* Filter for media */
713 const char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
715 ret = media_filter_create(&g_filter);
717 /* Set condition and collate
718 * Condition string : You can make where statement of sql.
719 * Colation : You can use collation when comparing.
720 * Ex) In case of FILE_NAME='Samsung' as condition string,
721 * if you want to compare with NOCASE collation,
722 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
723 * if you want to compare in case-sensitive,
724 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
726 ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
728 /* Collation of ordering
729 * If you want to get list, which is sorted by NOCASE,
730 * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_NOCASE);
732 * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
734 /* Able to set multi column to set order */
736 ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, "MEDIA_MODIFIED_TIME, MEDIA_DISPLAY_NAME", MEDIA_CONTENT_COLLATE_DEFAULT);
737 ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
738 ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TRACK_NUM_INT, MEDIA_CONTENT_COLLATE_DEFAULT);
739 ret = media_filter_set_storage(g_filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e");
741 /* Filter for group */
742 const char *g_condition = "TAG_NAME like \"\%my\%\"";
743 const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
745 ret = media_filter_create(&g_filter_g);
747 ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
752 int test_filter_destroy(void)
754 content_debug("\n============Filter Create============\n\n");
756 int ret = MEDIA_CONTENT_ERROR_NONE;
758 ret = media_filter_destroy(g_filter);
763 int test_connect_database(void)
765 int ret = MEDIA_CONTENT_ERROR_NONE;
767 content_debug("\n============DB Connection Test============\n\n");
769 ret = media_content_connect();
771 if (ret == MEDIA_CONTENT_ERROR_NONE)
772 content_debug("connection is success\n\n");
774 content_error("connection is failed\n\n");
779 int test_gallery_scenario(void)
781 int ret = MEDIA_CONTENT_ERROR_NONE;
783 filter_h filter = NULL;
786 GList *folder_list = NULL;
787 media_folder_h folder_handle = NULL;
789 /* First, Get folder list */
790 ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
791 if (ret != MEDIA_CONTENT_ERROR_NONE) {
792 content_error("media_folder_foreach_folder_from_db failed: %d", ret);
795 content_debug("media_folder_foreach_folder_from_db success!!");
796 char *folder_id = NULL;
798 for (i = 0; i < g_list_length(folder_list); i++) {
799 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
801 get_folder_meta(folder_handle, &folder_id);
803 ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
804 SAFE_FREE(folder_id);
805 if (ret != MEDIA_CONTENT_ERROR_NONE) {
806 content_error("media_folder_get_media_count_from_db failed: %d", ret);
809 content_debug("media count [%d] : %d", i, count);
814 /* To check performance */
815 struct timeval start, end;
816 gettimeofday(&start, NULL);
818 /* Second, Get all item list */
819 media_info_h media_handle = NULL;
820 GList *all_item_list = NULL;
822 media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
823 media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
824 ret = media_filter_create(&filter);
825 if (ret != MEDIA_CONTENT_ERROR_NONE) {
826 content_error("Fail to create filter");
829 ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
830 if (ret != MEDIA_CONTENT_ERROR_NONE) {
831 media_filter_destroy(filter);
832 content_error("Fail to set condition");
835 ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
836 if (ret != MEDIA_CONTENT_ERROR_NONE) {
837 media_filter_destroy(filter);
838 content_error("Fail to set order");
842 ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
843 if (ret != MEDIA_CONTENT_ERROR_NONE) {
844 content_error("media_info_foreach_media_from_db failed: %d", ret);
845 media_filter_destroy(filter);
848 content_debug("media_info_foreach_media_from_db success");
850 for (i = 0; i < g_list_length(all_item_list); i++) {
851 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
852 get_media_meta(media_handle);
856 media_filter_destroy(filter);
859 /* To check performance */
860 gettimeofday(&end, NULL);
861 long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
862 content_debug("Time : %ld\n", time);
864 /* Third, Get item list of a folder */
865 GList *item_list = NULL;
867 for (i = 0; i < g_list_length(folder_list); i++) {
869 char *folder_id = NULL;
870 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
872 get_folder_meta(folder_handle, &folder_id);
874 ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
875 SAFE_FREE(folder_id);
877 if (ret != MEDIA_CONTENT_ERROR_NONE) {
878 content_error("media_folder_foreach_media_from_db failed: %d", ret);
881 content_error("media_folder_foreach_media_from_db success!");
883 for (j = 0; j < g_list_length(item_list); j++) {
884 media_handle = (media_info_h)g_list_nth_data(item_list, j);
885 get_media_meta(media_handle);
891 media_tag_h tag_handle = NULL;
892 GList *tag_list = NULL;
893 GList *media_list_in_tag = NULL;
896 ret = media_tag_foreach_tag_from_db(filter, gallery_tag_item_cb, &tag_list);
898 if (ret != MEDIA_CONTENT_ERROR_NONE) {
899 content_error("media_tag_foreach_tag_from_db failed: %d", ret);
902 content_error("media_tag_foreach_tag_from_db success");
903 for (i = 0; i < g_list_length(tag_list); i++) {
904 tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
905 get_tag_meta(tag_handle);
907 ret = media_tag_get_tag_id(tag_handle, &tag_id);
908 if (ret != MEDIA_CONTENT_ERROR_NONE) {
909 ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag);
910 if (ret != MEDIA_CONTENT_ERROR_NONE) {
911 content_error("media_tag_foreach_media_from_db failed: %d", ret);
914 content_error("media_tag_foreach_media_from_db success");
916 media_info_h tag_media_handle;
918 for (j = 0; j < g_list_length(media_list_in_tag); j++) {
919 tag_media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, j);
920 get_media_meta(tag_media_handle);
927 /* Remove folder list */
929 for (i = 0; i < g_list_length(folder_list); i++) {
930 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
931 media_folder_destroy(folder_handle);
934 g_list_free(folder_list);
937 /* Remove all items list */
939 for (i = 0; i < g_list_length(all_item_list); i++) {
940 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
941 ret = media_info_destroy(media_handle);
942 if (ret != MEDIA_CONTENT_ERROR_NONE)
943 content_error("media_info_destroy failed: %d", ret);
946 g_list_free(all_item_list);
949 /* Remove items list */
951 for (i = 0; i < g_list_length(item_list); i++) {
952 media_handle = (media_info_h)g_list_nth_data(item_list, i);
953 ret = media_info_destroy(media_handle);
954 if (ret != MEDIA_CONTENT_ERROR_NONE)
955 content_error("media_info_destroy failed: %d", ret);
958 g_list_free(item_list);
961 /* Remove tag list */
963 for (i = 0; i < g_list_length(tag_list); i++) {
964 tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
965 ret = media_tag_destroy(tag_handle);
966 if (ret != MEDIA_CONTENT_ERROR_NONE)
967 content_error("error media_tag_destroy : [%d]", ret);
970 g_list_free(tag_list);
973 /* Remove media list in a tag */
974 if (media_list_in_tag) {
975 for (i = 0; i < g_list_length(media_list_in_tag); i++) {
976 media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, i);
977 ret = media_info_destroy(media_handle);
978 if (ret != MEDIA_CONTENT_ERROR_NONE)
979 content_error("media_info_destroy failed: %d", ret);
982 g_list_free(media_list_in_tag);
985 return MEDIA_CONTENT_ERROR_NONE;
988 /*Get All Music file. sort by Title and not case sensitive*/
989 int test_get_all_music_files(void)
991 int ret = MEDIA_CONTENT_ERROR_NONE;
996 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
998 ret = media_filter_create(&filter);
999 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1000 content_error("Fail to create filter");
1003 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED);
1004 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1005 media_filter_destroy(filter);
1006 content_error("Fail to set condition");
1009 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED);
1010 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1011 media_filter_destroy(filter);
1012 content_error("Fail to set order");
1017 ret = media_info_get_media_count_from_db(filter, &media_count);
1018 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1019 media_filter_destroy(filter);
1020 content_error("Fail to get media count");
1024 content_debug("media_count : [%d]", media_count);
1026 ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
1027 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1028 media_filter_destroy(filter);
1029 content_error("Fail to get media");
1033 ret = media_filter_destroy(filter);
1038 int test_media_info_operation(void)
1040 int ret = MEDIA_CONTENT_ERROR_NONE;
1041 int media_count = 0;
1043 content_debug("\n============Media info Test============\n\n");
1045 test_filter_create();
1047 ret = media_info_get_media_count_from_db(g_filter, &media_count);
1048 if (ret != MEDIA_CONTENT_ERROR_NONE)
1049 content_error("media_info_get_media_count_from_db failed: %d", ret);
1051 content_debug("media_count : [%d]", media_count);
1053 ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
1054 if (ret == MEDIA_CONTENT_ERROR_NONE)
1055 content_debug("media_info_foreach_media_from_db is success");
1057 content_error("media_info_foreach_media_from_db is failed");
1059 test_filter_destroy();
1064 int test_media_info_operation_2(void)
1066 int ret = MEDIA_CONTENT_ERROR_NONE;
1067 int bookmark_count = 0;
1069 content_debug("\n============Media info Test 2============\n\n");
1071 test_filter_create();
1075 char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1076 media_bookmark_insert_to_db(test_video_id, 100, thumbnail_path1);
1077 media_bookmark_insert_to_db(test_video_id, 200, thumbnail_path1);
1079 media_info_get_bookmark_count_from_db(test_video_id, g_filter_g, &bookmark_count);
1081 content_debug("bookmark_count : [%d]", bookmark_count);
1083 ret = media_info_foreach_bookmark_from_db(test_video_id, g_filter_g, bookmarks_cb, NULL);
1087 ret = media_info_get_tag_count_from_db(test_audio_id, g_filter_g, &bookmark_count);
1088 if (ret != MEDIA_CONTENT_ERROR_NONE)
1089 content_error("media_info_get_tag_count_from_db failed: %d", ret);
1091 content_debug("tag_count : [%d]", bookmark_count);
1093 ret = media_info_foreach_tag_from_db(test_audio_id, g_filter_g, tag_list_cb, NULL);
1094 if (ret != MEDIA_CONTENT_ERROR_NONE)
1095 content_error("media_info_foreach_tag_from_db failed: %d", ret);
1097 test_filter_destroy();
1102 int test_folder_operation(void)
1104 int ret = MEDIA_CONTENT_ERROR_NONE;
1105 filter_h filter = NULL;
1106 media_folder_h folder = NULL;
1107 char *folder_id = NULL;
1110 content_debug("\n============Folder Test============\n\n");
1112 test_filter_create();
1114 ret = media_filter_create(&filter);
1115 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1116 content_error("[ERROR] media_folder_filter_create is failed");
1120 media_filter_set_condition(filter, "(MEDIA_TYPE = 0 or MEDIA_TYPE = 1) and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
1121 media_filter_set_offset(filter, 0, 5);
1122 media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1123 media_filter_set_storage(filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e");
1125 ret = media_folder_get_folder_count_from_db(filter, &count);
1126 content_debug("Folder count : [%d]", count);
1128 ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
1130 filter_h m_filter = NULL;
1132 ret = media_filter_create(&m_filter);
1133 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1134 test_filter_destroy();
1135 media_filter_destroy(filter);
1136 content_error("[ERROR] media_info_filter_create is failed");
1140 media_filter_set_condition(m_filter, "MEDIA_TYPE=1 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
1141 media_filter_set_offset(m_filter, 0, 5);
1142 media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1144 ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
1145 if (ret != MEDIA_CONTENT_ERROR_NONE)
1146 content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret);
1148 media_filter_destroy(filter);
1149 media_filter_destroy(m_filter);
1151 test_filter_destroy();
1153 /* fix prevent: Resource Leak */
1154 SAFE_FREE(folder_id);
1159 int test_playlist_operation(void)
1161 int ret = MEDIA_CONTENT_ERROR_NONE;
1162 media_playlist_h playlist_1 = NULL;
1163 media_playlist_h playlist_2 = NULL;
1164 media_playlist_h playlist_3 = NULL;
1165 media_playlist_h playlist_4 = NULL;
1166 int playlist_id_1 = 0;
1167 int playlist_id_2 = 0;
1168 int playlist_id_3 = 0;
1169 const char *playlist_name_1 = "myPlaylist_1";
1170 const char *playlist_name_2 = "myPlaylist_2";
1171 const char *playlist_name_3 = "myPlaylist_3";
1172 int playlist_count = 0;
1173 int media_count = 0;
1179 filter_h filter = NULL;
1180 filter_h m_filter = NULL;
1182 content_debug("\n============Playlist Test============\n\n");
1184 /* Filter for playlist */
1186 const char *condition = "(MEDIA_TYPE=1 or MEDIA_TYPE=3)"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1188 ret = media_filter_create(&filter);
1189 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
1190 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_NAME, MEDIA_CONTENT_COLLATE_NOCASE);
1192 /* Create Playlist */
1193 media_playlist_insert_to_db(playlist_name_1, &playlist_1);
1194 media_playlist_insert_to_db(playlist_name_2, &playlist_2);
1195 media_playlist_insert_to_db(playlist_name_3, &playlist_3);
1197 if (playlist_1 != NULL) {
1198 /* Add media to Playlist */
1199 media_playlist_add_media(playlist_1, test_audio_id);
1200 media_playlist_add_media(playlist_1, test_audio_id);
1201 media_playlist_add_media(playlist_1, test_video_id);
1204 char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg"));
1205 media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1208 media_playlist_update_to_db(playlist_1);
1211 if (playlist_2 != NULL) {
1212 media_playlist_add_media(playlist_2, test_audio_id);
1213 media_playlist_add_media(playlist_2, test_audio_id);
1214 media_playlist_update_to_db(playlist_2);
1217 /* Get Playlist Count*/
1218 ret = media_playlist_get_playlist_count_from_db(filter, &playlist_count);
1220 content_debug("playlist_count [%d]", playlist_count);
1223 GList *playlist_id_list = NULL;
1224 media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, &playlist_id_list);
1225 /* 64bit build issue */
1227 /* Get Playlist id*/
1228 playlist_id_1 = (int)g_list_nth_data(playlist_id_list, 0);
1229 playlist_id_2 = (int)g_list_nth_data(playlist_id_list, 1);
1230 playlist_id_3 = (int)g_list_nth_data(playlist_id_list, 2);
1232 content_debug("playlist_id_1 [%d]", playlist_id_1);
1233 content_debug("playlist_id_2 [%d]", playlist_id_2);
1234 content_debug("playlist_id_3 [%d]", playlist_id_3);
1236 /* Export and import playlist */
1237 media_playlist_export_to_file(playlist_3, tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"));
1238 media_playlist_import_from_file(tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"), "playlist_4", &playlist_4);
1240 /* Filter for media*/
1241 ret = media_filter_create(&m_filter);
1243 ret = media_filter_set_condition(m_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1245 ret = media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_MEMBER_ORDER, MEDIA_CONTENT_COLLATE_DEFAULT);
1247 /* Get media count */
1248 media_playlist_get_media_count_from_db(playlist_id_1, m_filter, &media_count);
1249 content_debug("playlist_1_media_count [%d]", media_count);
1251 media_playlist_get_media_count_from_db(playlist_id_2, m_filter, &media_count);
1252 content_debug("playlist_2_media_count [%d]", media_count);
1254 media_playlist_get_media_count_from_db(playlist_id_3, m_filter, &media_count);
1255 content_debug("playlist_3_media_count [%d]", media_count);
1257 /* Get media of playlist */
1258 GList *playlist_member_id_list = NULL;
1259 GList *playlist_member_id_list_1 = NULL;
1261 media_playlist_foreach_media_from_db(playlist_id_1, m_filter, playlist_item_cb, &playlist_member_id_list);
1262 media_playlist_foreach_media_from_db(playlist_id_2, m_filter, playlist_item_cb, &playlist_member_id_list_1);
1264 int playlist_member_id_1_1 = 0;
1265 int playlist_member_id_1_2 = 0;
1266 int playlist_member_id_1_3 = 0;
1267 int playlist_member_id_2_1 = 0;
1268 int playlist_member_id_2_2 = 0;
1269 /* 64bit build issue */
1271 playlist_member_id_1_1 = (int)g_list_nth_data(playlist_member_id_list, 0);
1272 playlist_member_id_1_2 = (int)g_list_nth_data(playlist_member_id_list, 1);
1273 playlist_member_id_1_3 = (int)g_list_nth_data(playlist_member_id_list, 2);
1274 playlist_member_id_2_1 = (int)g_list_nth_data(playlist_member_id_list_1, 0);
1275 playlist_member_id_2_2 = (int)g_list_nth_data(playlist_member_id_list_1, 1);
1277 content_debug("playlist_member_id_1_1 [%d]", playlist_member_id_1_1);
1278 content_debug("playlist_member_id_1_2 [%d]", playlist_member_id_1_2);
1279 content_debug("playlist_member_id_1_3 [%d]", playlist_member_id_1_3);
1280 content_debug("playlist_member_id_2_1 [%d]", playlist_member_id_2_1);
1281 content_debug("playlist_member_id_2_2 [%d]", playlist_member_id_2_2);
1283 media_playlist_get_play_order(playlist_1, playlist_member_id_1_1, &order_1);
1284 media_playlist_get_play_order(playlist_1, playlist_member_id_1_2, &order_2);
1285 media_playlist_get_play_order(playlist_1, playlist_member_id_1_3, &order_3);
1286 media_playlist_get_play_order(playlist_2, playlist_member_id_2_1, &order_4);
1287 media_playlist_get_play_order(playlist_2, playlist_member_id_2_2, &order_5);
1288 content_debug("order_1 [%d] order_2 [%d] order_3 [%d] order_4 [%d] order_5 [%d]", order_1, order_2, order_3, order_4, order_5);
1290 /* Update Playlist */
1291 media_playlist_remove_media(playlist_2, playlist_member_id_2_1);
1292 media_playlist_add_media(playlist_2, test_video_id);
1293 media_playlist_set_name(playlist_2, "test_playlist");
1294 media_playlist_set_play_order(playlist_2, playlist_member_id_2_2, order_5+100);
1295 media_playlist_update_to_db(playlist_2);
1297 /* Get Updated Playlist*/
1298 media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, NULL);
1300 /* deletes the playlist */
1302 media_playlist_delete_from_db(playlist_id_1);
1303 media_playlist_delete_from_db(playlist_id_2);
1306 if (playlist_1 != NULL)
1307 media_playlist_destroy(playlist_1);
1308 if (playlist_2 != NULL)
1309 media_playlist_destroy(playlist_2);
1310 if (playlist_3 != NULL)
1311 media_playlist_destroy(playlist_3);
1312 if (playlist_4 != NULL)
1313 media_playlist_destroy(playlist_4);
1315 g_list_free(playlist_id_list);
1316 g_list_free(playlist_member_id_list);
1317 g_list_free(playlist_member_id_list_1);
1320 ret = media_filter_destroy(filter);
1321 if (m_filter != NULL)
1322 ret = media_filter_destroy(m_filter);
1327 int test_playlist_operation_v2(void)
1329 int ret = MEDIA_CONTENT_ERROR_NONE;
1330 media_playlist_h playlist_1 = NULL;
1331 const char *playlist_name_1 = "myPlaylist_1";
1332 const char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1333 int playlist_id = 0;
1335 content_debug("\n============Playlist Test V2============\n\n");
1337 ret = media_playlist_create(&playlist_1);
1338 if (ret != MEDIA_CONTENT_ERROR_NONE)
1339 content_error("error media_playlist_create : [%d]", ret);
1341 ret = media_playlist_set_name(playlist_1, playlist_name_1);
1342 if (ret != MEDIA_CONTENT_ERROR_NONE)
1343 content_error("error media_playlist_set_name : [%d]", ret);
1345 ret = media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1346 if (ret != MEDIA_CONTENT_ERROR_NONE)
1347 content_error("error media_playlist_set_thumbnail_path : [%d]", ret);
1349 ret = media_playlist_insert_to_db_v2(playlist_1);
1350 if (ret != MEDIA_CONTENT_ERROR_NONE)
1351 content_error("error media_playlist_insert_to_db_v2 : [%d]", ret);
1353 ret = media_playlist_set_name(playlist_1, "myPlaylist_3");
1354 if (ret != MEDIA_CONTENT_ERROR_NONE)
1355 content_error("error media_playlist_set_name : [%d]", ret);
1357 ret = media_playlist_get_playlist_id(playlist_1, &playlist_id);
1358 if (ret != MEDIA_CONTENT_ERROR_NONE)
1359 content_error("error media_playlist_get_playlist_id : [%d]", ret);
1361 ret = media_playlist_update_to_db_v2(playlist_id, playlist_1);
1362 if (ret != MEDIA_CONTENT_ERROR_NONE)
1363 content_error("error media_playlist_update_to_db_v2 : [%d]", ret);
1365 ret = media_playlist_destroy(playlist_1);
1366 if (ret != MEDIA_CONTENT_ERROR_NONE)
1367 content_error("error media_playlist_destroy : [%d]", ret);
1372 int test_tag_operation(void)
1374 int ret = MEDIA_CONTENT_ERROR_NONE;
1381 const char *tag_name_1 = "myTag_1";
1382 const char *tag_name_2 = "myTag_2";
1383 const char *tag_name_3 = "myTag_3";
1385 int media_count = 0;
1388 content_debug("\n============Tag Test============\n\n");
1390 const char *g_condition = "TAG_NAME like \"%%my%%\"";
1392 ret = media_filter_create(&filter);
1394 ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1396 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
1399 ret = media_tag_insert_to_db(tag_name_1, &tag_1);
1400 if (ret != MEDIA_CONTENT_ERROR_NONE)
1401 content_error("error media_tag_insert_to_db : [%d]", ret);
1402 ret = media_tag_insert_to_db(tag_name_2, &tag_2);
1403 if (ret != MEDIA_CONTENT_ERROR_NONE)
1404 content_error("error media_tag_insert_to_db : [%d]", ret);
1405 ret = media_tag_insert_to_db(tag_name_3, &tag_3);
1406 if (ret != MEDIA_CONTENT_ERROR_NONE)
1407 content_error("error media_tag_insert_to_db : [%d]", ret);
1409 /* Add media to Tag */
1410 ret = media_tag_add_media(tag_1, test_audio_id);
1411 if (ret != MEDIA_CONTENT_ERROR_NONE)
1412 content_error("error media_tag_add_media : [%d]", ret);
1413 ret = media_tag_add_media(tag_1, test_video_id);
1414 if (ret != MEDIA_CONTENT_ERROR_NONE)
1415 content_error("error media_tag_add_media : [%d]", ret);
1416 ret = media_tag_update_to_db(tag_1);
1417 if (ret != MEDIA_CONTENT_ERROR_NONE)
1418 content_error("error media_tag_update_to_db : [%d]", ret);
1420 ret = media_tag_add_media(tag_2, test_audio_id);
1421 if (ret != MEDIA_CONTENT_ERROR_NONE)
1422 content_error("error media_tag_add_media : [%d]", ret);
1423 ret = media_tag_update_to_db(tag_2);
1424 if (ret != MEDIA_CONTENT_ERROR_NONE)
1425 content_error("error media_tag_update_to_db : [%d]", ret);
1428 ret = media_tag_get_tag_count_from_db(filter, &tag_count);
1429 if (ret != MEDIA_CONTENT_ERROR_NONE)
1430 content_error("error media_tag_get_tag_count_from_db : [%d]", ret);
1432 content_debug("tag_count [%d]", tag_count);
1435 ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1436 if (ret != MEDIA_CONTENT_ERROR_NONE)
1437 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1440 ret = media_tag_get_tag_id(tag_1, &tag_id_1);
1441 if (ret != MEDIA_CONTENT_ERROR_NONE)
1442 content_error("error media_tag_get_tag_id : [%d]", ret);
1444 content_debug("tag_id_1 [%d]", tag_id_1);
1446 ret = media_tag_get_tag_id(tag_2, &tag_id_2);
1447 if (ret != MEDIA_CONTENT_ERROR_NONE)
1448 content_error("error media_tag_get_tag_id : [%d]", ret);
1450 content_debug("tag_id_2 [%d]", tag_id_2);
1452 ret = media_tag_get_tag_id(tag_3, &tag_id_3);
1453 if (ret != MEDIA_CONTENT_ERROR_NONE)
1454 content_error("error media_tag_get_tag_id : [%d]", ret);
1456 content_debug("tag_id_3 [%d]", tag_id_3);
1458 /* Get media count */
1459 ret = media_tag_get_media_count_from_db(tag_id_1, NULL, &media_count);
1460 if (ret != MEDIA_CONTENT_ERROR_NONE)
1461 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1463 content_debug("tag_1_media_count [%d]", media_count);
1465 ret = media_tag_get_media_count_from_db(tag_id_2, NULL, &media_count);
1466 if (ret != MEDIA_CONTENT_ERROR_NONE)
1467 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1469 content_debug("tag_2_media_count [%d]", media_count);
1471 /* Get media of Tag */
1472 ret = media_tag_foreach_media_from_db(tag_id_1, NULL, media_item_cb, NULL);
1473 if (ret != MEDIA_CONTENT_ERROR_NONE)
1474 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1476 ret = media_tag_foreach_media_from_db(tag_id_2, NULL, media_item_cb, NULL);
1477 if (ret != MEDIA_CONTENT_ERROR_NONE)
1478 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1481 ret = media_tag_add_media(tag_2, test_video_id);
1482 if (ret != MEDIA_CONTENT_ERROR_NONE)
1483 content_error("error media_tag_add_media : [%d]", ret);
1484 ret = media_tag_set_name(tag_2, "test_tag");
1485 if (ret != MEDIA_CONTENT_ERROR_NONE)
1486 content_error("error media_tag_set_name : [%d]", ret);
1487 ret = media_tag_update_to_db(tag_2);
1488 if (ret != MEDIA_CONTENT_ERROR_NONE)
1489 content_error("error media_tag_update_to_db : [%d]", ret);
1491 /* Get Updated Tag*/
1492 ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1493 if (ret != MEDIA_CONTENT_ERROR_NONE)
1494 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1496 /* deletes the tag */
1497 ret = media_tag_delete_from_db(tag_id_1);
1498 if (ret != MEDIA_CONTENT_ERROR_NONE)
1499 content_error("error media_tag_delete_from_db : [%d]", ret);
1500 ret = media_tag_delete_from_db(tag_id_2);
1501 if (ret != MEDIA_CONTENT_ERROR_NONE)
1502 content_error("error media_tag_delete_from_db : [%d]", ret);
1504 ret = media_tag_destroy(tag_1);
1505 if (ret != MEDIA_CONTENT_ERROR_NONE)
1506 content_error("error media_tag_destroy : [%d]", ret);
1507 ret = media_tag_destroy(tag_2);
1508 if (ret != MEDIA_CONTENT_ERROR_NONE)
1509 content_error("error media_tag_destroy : [%d]", ret);
1510 ret = media_tag_destroy(tag_3);
1511 if (ret != MEDIA_CONTENT_ERROR_NONE)
1512 content_error("error media_tag_destroy : [%d]", ret);
1513 ret = media_filter_destroy(filter);
1514 if (ret != MEDIA_CONTENT_ERROR_NONE)
1515 content_error("error media_filter_destroy : [%d]", ret);
1520 int test_tag_operation_v2(void)
1522 int ret = MEDIA_CONTENT_ERROR_NONE;
1524 const char *tag_name_1 = "myTag_1";
1527 content_debug("\n============Tag Test V2============\n\n");
1530 ret = media_tag_create(&tag_1);
1531 if (ret != MEDIA_CONTENT_ERROR_NONE)
1532 content_error("error media_tag_create : [%d]", ret);
1534 ret = media_tag_set_name(tag_1, tag_name_1);
1535 if (ret != MEDIA_CONTENT_ERROR_NONE)
1536 content_error("error media_tag_set_name : [%d]", ret);
1538 /* Add media to Tag */
1539 ret = media_tag_add_media(tag_1, test_audio_id);
1540 if (ret != MEDIA_CONTENT_ERROR_NONE)
1541 content_error("error media_tag_add_media : [%d]", ret);
1543 ret = media_tag_add_media(tag_1, test_video_id);
1544 if (ret != MEDIA_CONTENT_ERROR_NONE)
1545 content_error("error media_tag_add_media : [%d]", ret);
1547 ret = media_tag_insert_to_db_v2(tag_1);
1548 if (ret != MEDIA_CONTENT_ERROR_NONE)
1549 content_error("error media_tag_insert_to_db_v2 : [%d]", ret);
1552 ret = media_tag_get_tag_id(tag_1, &tag_id);
1553 if (ret != MEDIA_CONTENT_ERROR_NONE)
1554 content_error("error media_tag_get_tag_id : [%d]", ret);
1556 ret = media_tag_remove_media(tag_1, test_video_id);
1557 if (ret != MEDIA_CONTENT_ERROR_NONE)
1558 content_error("error media_tag_add_media : [%d]", ret);
1560 ret = media_tag_update_to_db_v2(tag_id, tag_1);
1561 if (ret != MEDIA_CONTENT_ERROR_NONE)
1562 content_error("error media_tag_update_to_db_v2 : [%d]", ret);
1565 ret = media_tag_destroy(tag_1);
1566 if (ret != MEDIA_CONTENT_ERROR_NONE)
1567 content_error("error media_tag_destroy : [%d]", ret);
1572 static void __bookmark_handle_free(gpointer data)
1574 media_bookmark_h handle = (media_bookmark_h) data;
1575 media_bookmark_destroy(handle);
1578 int test_bookmark_operation(void)
1580 /* bookmark is only supported for video information. */
1581 int ret = MEDIA_CONTENT_ERROR_NONE;
1582 int bookmark_count = 0;
1584 GList *all_item_list = NULL;
1587 content_debug("\n============Bookmark Test============\n\n");
1589 const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
1591 ret = media_filter_create(&filter);
1592 if (ret != MEDIA_CONTENT_ERROR_NONE)
1593 content_error("error media_filter_create : [%d]", ret);
1595 ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1596 if (ret != MEDIA_CONTENT_ERROR_NONE)
1597 content_error("error media_filter_set_condition : [%d]", ret);
1599 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, BOOKMARK_MARKED_TIME, MEDIA_CONTENT_COLLATE_DEFAULT);
1600 if (ret != MEDIA_CONTENT_ERROR_NONE)
1601 content_error("error media_filter_set_order : [%d]", ret);
1603 /* insert bookmark to video */
1604 const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1605 ret = media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1);
1606 if (ret != MEDIA_CONTENT_ERROR_NONE)
1607 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1609 ret = media_bookmark_insert_to_db(test_video_id, 600, thumbnail_path1);
1610 if (ret != MEDIA_CONTENT_ERROR_NONE)
1611 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1613 ret = media_bookmark_get_bookmark_count_from_db(filter, &bookmark_count);
1614 if (ret != MEDIA_CONTENT_ERROR_NONE)
1615 content_error("error media_bookmark_get_bookmark_count_from_db : [%d]", ret);
1617 content_debug("bookmark_count = [%d]", bookmark_count);
1619 ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, &all_item_list);
1620 if (ret != MEDIA_CONTENT_ERROR_NONE)
1621 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1623 for (idx = 0; idx < g_list_length(all_item_list); idx++) {
1624 media_bookmark_h bookmark_handle;
1625 bookmark_handle = (media_bookmark_h)g_list_nth_data(all_item_list, idx);
1627 ret = media_bookmark_set_name(bookmark_handle, "test 1");
1628 if (ret != MEDIA_CONTENT_ERROR_NONE)
1629 content_error("error media_bookmark_set_name : [%d]", ret);
1631 ret = media_bookmark_update_to_db(bookmark_handle);
1632 if (ret != MEDIA_CONTENT_ERROR_NONE)
1633 content_error("error media_bookmark_update_to_db : [%d]", ret);
1637 g_list_free_full(all_item_list, __bookmark_handle_free);
1639 ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, NULL);
1640 if (ret != MEDIA_CONTENT_ERROR_NONE)
1641 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1643 ret = media_filter_destroy(filter);
1644 if (ret != MEDIA_CONTENT_ERROR_NONE)
1645 content_error("error media_filter_destroy : [%d]", ret);
1650 int test_bookmark_operation_v2(void)
1652 content_debug("\n============Bookmark Test V2============\n\n");
1654 int ret = MEDIA_CONTENT_ERROR_NONE;
1655 media_bookmark_h bookmark = NULL;
1656 const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1658 ret = media_bookmark_create(test_video_id, 400, &bookmark);
1659 if (ret != MEDIA_CONTENT_ERROR_NONE)
1660 content_error("error media_bookmark_create : [%d]", ret);
1662 ret = media_bookmark_set_name(bookmark, "test bookmark");
1663 if (ret != MEDIA_CONTENT_ERROR_NONE)
1664 content_error("error media_bookmark_set_name : [%d]", ret);
1666 ret = media_bookmark_set_thumbnail_path(bookmark, thumbnail_path1);
1667 if (ret != MEDIA_CONTENT_ERROR_NONE)
1668 content_error("error media_bookmark_set_thumbnail_path : [%d]", ret);
1670 ret = media_bookmark_insert_to_db_v2(bookmark);
1671 if (ret != MEDIA_CONTENT_ERROR_NONE)
1672 content_error("error media_bookmark_insert_to_db_v2 : [%d]", ret);
1674 ret = media_bookmark_set_name(bookmark, "test bookmark 2");
1675 if (ret != MEDIA_CONTENT_ERROR_NONE)
1676 content_error("error media_bookmark_set_name : [%d]", ret);
1678 ret = media_bookmark_update_to_db(bookmark);
1679 if (ret != MEDIA_CONTENT_ERROR_NONE)
1680 content_error("error media_bookmark_update_to_db : [%d]", ret);
1682 ret = media_bookmark_destroy(bookmark);
1683 if (ret != MEDIA_CONTENT_ERROR_NONE)
1684 content_error("error media_bookmark_destroy : [%d]", ret);
1689 int test_album_list(void)
1691 content_debug("\n============Album Test============\n\n");
1693 int ret = MEDIA_CONTENT_ERROR_NONE;
1694 int album_count = 0;
1698 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1700 ret = media_filter_create(&filter);
1701 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1702 content_error("Fail to create filter");
1705 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1706 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1707 media_filter_destroy(filter);
1708 content_error("Fail to set condition");
1711 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
1712 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1713 media_filter_destroy(filter);
1714 content_error("Fail to set order");
1718 ret = media_album_get_album_count_from_db(filter, &album_count);
1719 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1720 media_filter_destroy(filter);
1723 content_debug("album_count [%d]", album_count);
1726 ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
1727 if (ret != MEDIA_CONTENT_ERROR_NONE)
1728 content_error("error media_album_foreach_album_from_db : [%d]", ret);
1730 ret = media_filter_destroy(filter);
1731 if (ret != MEDIA_CONTENT_ERROR_NONE)
1732 content_error("error media_filter_destroy : [%d]", ret);
1737 int test_group_operation(void)
1739 content_debug("\n============Group Test============\n\n");
1741 int ret = MEDIA_CONTENT_ERROR_NONE;
1742 int group_count = 0;
1745 ret = test_filter_create();
1746 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1747 content_error("[error(0x%08x)", ret);
1751 for (idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) {
1752 ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
1753 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1754 test_filter_destroy();
1755 content_error("media_group_get_group_count_from_db fail. ret=[%d] idx=[%d]", ret, idx);
1758 content_debug("[%2d]group_count [%d]", idx, group_count);
1761 ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
1762 if (ret != MEDIA_CONTENT_ERROR_NONE)
1763 content_error("media_group_foreach_group_from_db failed: %d", ret);
1765 ret = test_filter_destroy();
1770 int test_update_operation()
1772 int ret = MEDIA_CONTENT_ERROR_NONE;
1774 media_info_h media_handle = NULL;
1775 GList *all_item_list = NULL;
1777 /* Get all item list */
1778 ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
1779 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1780 content_error("media_info_foreach_media_from_db failed: %d", ret);
1783 content_debug("media_info_foreach_media_from_db success");
1785 for (i = 0; i < g_list_length(all_item_list); i++) {
1786 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
1787 get_media_meta(media_handle);
1791 return MEDIA_CONTENT_ERROR_NONE;
1794 int test_insert(void)
1796 int ret = MEDIA_CONTENT_ERROR_NONE;
1797 const char *path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1799 const char *path = tzplatform_mkpath(TZ_USER_DOCUMENTS, "other.txt"));
1802 media_info_h media_item = NULL;
1803 content_debug("\n============DB Insert Test============\n\n");
1805 ret = media_info_insert_to_db(path, &media_item);
1807 if ((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) {
1808 content_debug("Insertion is success");
1810 content_error("Insertion is failed");
1811 ret = media_info_destroy(media_item);
1815 char *media_id = NULL;
1817 ret = media_info_get_media_id(media_item, &media_id);
1818 if (ret != MEDIA_CONTENT_ERROR_NONE)
1819 content_error("media_info_get_media_id failed: %d", ret);
1821 content_debug("Media ID: %s", media_id);
1823 SAFE_FREE(media_id);
1825 ret = media_info_update_to_db(media_item);
1826 if (ret == MEDIA_CONTENT_ERROR_NONE)
1827 content_debug("media_info_update_to_db is success");
1829 content_error("media_info_update_to_db is failed");
1831 ret = media_info_destroy(media_item);
1832 if (ret != MEDIA_CONTENT_ERROR_NONE)
1833 content_error("media_info_destroy failed: %d", ret);
1840 int ret = MEDIA_CONTENT_ERROR_NONE;
1841 const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
1842 const char *dst_path = tzplatform_mkpath(TZ_USER_IMAGES, "XX/Default1.jpg");
1843 media_info_h move_media = NULL;
1845 ret = media_info_get_media_from_db(move_media_id, &move_media);
1846 if (ret == MEDIA_CONTENT_ERROR_NONE)
1847 content_debug("media_info_get_media_from_db success");
1849 content_error("media_info_get_media_from_db failed: %d", ret);
1851 content_debug("\n============DB Move Test============\n\n");
1854 ret = media_info_move_to_db(move_media, dst_path);
1856 if (ret == MEDIA_CONTENT_ERROR_NONE)
1857 content_debug("Move is success");
1859 content_error("Move is failed");
1861 ret = media_info_destroy(move_media);
1863 content_debug("There is no item : %s", move_media_id);
1869 void thumbnail_completed_cb(media_content_error_e error, const char *path, void *user_data)
1871 char *thumbnail_path = NULL;
1872 int ret = MEDIA_CONTENT_ERROR_NONE;
1875 content_debug("=================[%d][%d]", g_media_cnt, g_cnt);
1876 content_debug("error_code [%d]", error);
1877 content_debug("thumbnail_path [%s]", path);
1878 if (user_data != NULL) {
1879 media_info_h media = (media_info_h)user_data;
1880 ret = media_info_get_thumbnail_path(media, &thumbnail_path);
1881 if (ret != MEDIA_CONTENT_ERROR_NONE)
1882 content_error("media_info_get_thumbnail_path failed: %d", ret);
1884 content_debug("thumbnail_path get from media[%s]", thumbnail_path);
1885 SAFE_FREE(thumbnail_path);
1886 ret = media_info_destroy(media);
1887 if (ret != MEDIA_CONTENT_ERROR_NONE)
1888 content_error("media_info_destroy failed: %d", ret);
1891 if (g_cnt == g_media_cnt)
1892 g_main_loop_quit(g_loop);
1897 bool thumbnail_create_cb(media_info_h media, void *user_data)
1899 char *media_id = NULL;
1900 media_info_h dst = NULL;
1901 int ret = MEDIA_CONTENT_ERROR_NONE;
1903 if (media == NULL) {
1904 content_debug("NO Item");
1908 ret = media_info_get_media_id(media, &media_id);
1909 if (ret != MEDIA_CONTENT_ERROR_NONE)
1910 content_error("media_info_get_media_id failed: %d", ret);
1912 content_debug("media_id : [%s]", media_id);
1914 ret = media_info_clone(&dst, media);
1915 if (ret != MEDIA_CONTENT_ERROR_NONE)
1916 content_error("media_info_clone failed: %d", ret);
1918 ret = media_info_create_thumbnail(dst, thumbnail_completed_cb, dst);
1919 if (ret != MEDIA_CONTENT_ERROR_NONE)
1920 content_error("media_info_create_thumbnail failed: %d", ret);
1923 /* fix prevent: Resource leak */
1924 SAFE_FREE(media_id);
1929 bool thumbnail_cancel_cb(media_info_h media, void *user_data)
1931 int ret = MEDIA_CONTENT_ERROR_NONE;
1933 char *media_id = NULL;
1934 media_info_h dst = NULL;
1938 if (media == NULL) {
1939 content_debug("NO Item");
1943 ret = media_info_get_media_id(media, &media_id);
1944 if (ret != MEDIA_CONTENT_ERROR_NONE)
1945 content_error("media_info_get_media_id failed: %d", ret);
1947 content_debug("media_id : [%s]", media_id);
1949 ret = media_info_clone(&dst, media);
1950 if (ret != MEDIA_CONTENT_ERROR_NONE)
1951 content_error("media_info_clone failed: %d", ret);
1953 ret = media_info_cancel_thumbnail(dst);
1954 if (ret != MEDIA_CONTENT_ERROR_NONE)
1955 content_error("media_info_cancel_thumbnail failed: %d", ret);
1957 ret = media_info_destroy(dst);
1958 if (ret != MEDIA_CONTENT_ERROR_NONE)
1959 content_error("media_info_destroy failed: %d", ret);
1961 if (g_cnt == g_media_cnt)
1962 g_main_loop_quit(g_loop);
1964 /* fix prevent: Resource leak */
1965 SAFE_FREE(media_id);
1970 gboolean create_thumbnail_start(gpointer data)
1972 int ret = MEDIA_CONTENT_ERROR_NONE;
1974 ret = media_info_foreach_media_from_db(g_filter, thumbnail_create_cb, NULL);
1976 if (ret == MEDIA_CONTENT_ERROR_NONE)
1977 content_debug("media_info_foreach_media_from_db is success");
1979 content_error("media_info_foreach_media_from_db is failed");
1984 gboolean cancel_thumbnail_start(gpointer data)
1986 int ret = MEDIA_CONTENT_ERROR_NONE;
1988 ret = media_info_foreach_media_from_db(g_filter, thumbnail_cancel_cb, NULL);
1990 if (ret == MEDIA_CONTENT_ERROR_NONE)
1991 content_debug("media_info_foreach_media_from_db is success");
1993 content_error("media_info_foreach_media_from_db is failed");
1998 int test_create_thumbnail(int cancel)
2000 int ret = MEDIA_CONTENT_ERROR_NONE;
2001 GSource *source = NULL;
2002 GMainContext *context = NULL;
2004 test_filter_create();
2006 ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt);
2007 if (ret != MEDIA_CONTENT_ERROR_NONE)
2008 content_error("media_info_get_media_count_from_db failed: %d", ret);
2010 content_debug("media_count : [%d]", g_media_cnt);
2012 g_loop = g_main_loop_new(NULL, FALSE);
2013 context = g_main_loop_get_context(g_loop);
2014 source = g_idle_source_new();
2015 g_source_set_callback(source, create_thumbnail_start, NULL, NULL);
2016 g_source_attach(source, context);
2018 /* Logic to cancel */
2020 GSource *cancel_src = NULL;
2021 cancel_src = g_idle_source_new();
2022 g_source_set_callback(cancel_src, cancel_thumbnail_start, NULL, NULL);
2023 g_source_attach(cancel_src, context);
2026 g_main_loop_run(g_loop);
2027 g_main_loop_unref(g_loop);
2029 test_filter_destroy();
2034 bool face_cb(media_face_h face, void *user_data)
2036 get_face_meta(face);
2041 void face_detection_complete_cb(media_content_error_e error, int count, void *user_data)
2043 int ret = MEDIA_CONTENT_ERROR_NONE;
2046 content_debug("=================[%d][%d]", g_media_cnt, g_cnt);
2047 content_debug("error_code [%d]", error);
2048 content_debug("face_count [%d]", count);
2050 content_debug("No faces are detected!");
2051 } else if (user_data != NULL) {
2052 media_info_h media = (media_info_h)user_data;
2053 char *media_id = NULL;
2054 ret = media_info_get_media_id(media, &media_id);
2055 if (ret != MEDIA_CONTENT_ERROR_NONE)
2056 content_error("media_info_get_media_id failed: %d", ret);
2057 if (media_id != NULL) {
2058 ret = media_info_foreach_face_from_db(media_id, NULL, face_cb, NULL);
2059 SAFE_FREE(media_id);
2060 if (ret != MEDIA_CONTENT_ERROR_NONE)
2061 content_error("media_info_foreach_face_from_db failed: %d", ret);
2063 ret = media_info_destroy(media);
2064 if (ret != MEDIA_CONTENT_ERROR_NONE)
2065 content_error("media_info_destroy failed: %d", ret);
2068 if (g_cnt == g_media_cnt)
2069 g_main_loop_quit(g_loop);
2074 bool start_face_detection_cb(media_info_h media, void *user_data)
2076 char *media_id = NULL;
2077 media_info_h dst = NULL;
2078 int ret = MEDIA_CONTENT_ERROR_NONE;
2080 if (media == NULL) {
2081 content_debug("NO Item");
2085 ret = media_info_get_media_id(media, &media_id);
2086 if (ret != MEDIA_CONTENT_ERROR_NONE)
2087 content_error("media_info_get_media_id failed: %d", ret);
2089 content_debug("media_id : [%s]", media_id);
2091 ret = media_info_clone(&dst, media);
2092 if (ret != MEDIA_CONTENT_ERROR_NONE)
2093 content_error("media_info_clone failed: %d", ret);
2095 GList **list = (GList**)user_data;
2096 *list = g_list_append(*list, dst);
2098 /* fix prevent: Resource leak */
2099 SAFE_FREE(media_id);
2104 bool cancel_face_detection_cb(media_info_h media, void *user_data)
2106 int ret = MEDIA_CONTENT_ERROR_NONE;
2108 char *media_id = NULL;
2109 media_info_h dst = NULL;
2113 if (media == NULL) {
2114 content_debug("NO Item");
2118 ret = media_info_get_media_id(media, &media_id);
2119 if (ret != MEDIA_CONTENT_ERROR_NONE)
2120 content_error("media_info_get_media_id failed: %d", ret);
2122 content_debug("media_id : [%s]", media_id);
2124 ret = media_info_clone(&dst, media);
2125 if (ret != MEDIA_CONTENT_ERROR_NONE)
2126 content_error("media_info_clone failed: %d", ret);
2128 ret = media_info_cancel_face_detection(dst);
2129 if (ret != MEDIA_CONTENT_ERROR_NONE)
2130 content_error("media_info_cancel_face_detection failed: %d", ret);
2132 ret = media_info_destroy(dst);
2133 if (ret != MEDIA_CONTENT_ERROR_NONE)
2134 content_error("media_info_destroy failed: %d", ret);
2136 if (g_cnt == g_media_cnt)
2137 g_main_loop_quit(g_loop);
2139 /* fix prevent: Resource leak */
2140 SAFE_FREE(media_id);
2145 gboolean face_detection_start(gpointer data)
2147 int ret = MEDIA_CONTENT_ERROR_NONE;
2148 GList *all_item_list = NULL;
2151 ret = media_info_foreach_media_from_db(g_filter, start_face_detection_cb, &all_item_list);
2153 if (ret == MEDIA_CONTENT_ERROR_NONE)
2154 content_debug("media_info_foreach_media_from_db is success");
2156 content_error("media_info_foreach_media_from_db is failed");
2158 for (idx = 0; idx < g_list_length(all_item_list); idx++) {
2159 media_info_h media_handle = NULL;
2161 media_handle = (media_info_h)g_list_nth_data(all_item_list, idx);
2163 ret = media_info_start_face_detection(media_handle, face_detection_complete_cb, NULL);
2164 if (ret != MEDIA_CONTENT_ERROR_NONE)
2165 content_error("media_info_start_face_detection failed: %d", ret);
2172 gboolean face_detection_cancel(gpointer data)
2174 int ret = MEDIA_CONTENT_ERROR_NONE;
2176 ret = media_info_foreach_media_from_db(g_filter, cancel_face_detection_cb, NULL);
2178 if (ret == MEDIA_CONTENT_ERROR_NONE)
2179 content_debug("media_info_foreach_media_from_db is success");
2181 content_error("media_info_foreach_media_from_db is failed");
2186 int test_start_face_detection(int cancel)
2188 int ret = MEDIA_CONTENT_ERROR_NONE;
2189 GSource *source = NULL;
2190 GMainContext *context = NULL;
2192 test_filter_create();
2194 ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt);
2195 if (ret != MEDIA_CONTENT_ERROR_NONE)
2196 content_error("media_info_get_media_count_from_db failed: %d", ret);
2198 content_debug("media_count : [%d]", g_media_cnt);
2200 if (g_media_cnt == 0)
2203 g_loop = g_main_loop_new(NULL, FALSE);
2204 context = g_main_loop_get_context(g_loop);
2205 source = g_idle_source_new();
2206 g_source_set_callback(source, face_detection_start, NULL, NULL);
2207 g_source_attach(source, context);
2209 /* Logic to cancel */
2211 GSource *cancel_src = NULL;
2212 cancel_src = g_idle_source_new();
2213 g_source_set_callback(cancel_src, face_detection_cancel, NULL, NULL);
2214 g_source_attach(cancel_src, context);
2217 g_main_loop_run(g_loop);
2218 g_main_loop_unref(g_loop);
2221 test_filter_destroy();
2226 int test_ebook_text_finder(const char *keyword)
2228 int ret = MEDIA_CONTENT_ERROR_NONE;
2229 char **book_path_list = NULL;
2230 unsigned int book_path_len = 0;
2232 media_info_h media = NULL;
2233 book_meta_h book = NULL;
2234 char *s_value = NULL;
2235 long long ms_time = 0;
2236 struct timeval start_time;
2237 struct timeval end_time;
2239 gettimeofday(&start_time, NULL);
2241 ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
2242 if (ret == MEDIA_CONTENT_ERROR_NONE)
2243 content_debug("book_meta_get_path_with_keyword is success");
2245 content_error("book_meta_get_path_with_keyword is failed");
2247 gettimeofday(&end_time, NULL);
2249 for (i = 0; i < book_path_len; i++) {
2250 ret = media_info_get_media_from_db_by_path(book_path_list[i], &media);
2251 if (ret != MEDIA_CONTENT_ERROR_NONE)
2254 content_debug("===============================");
2255 content_debug("[%d] %s", i, book_path_list[i]);
2256 content_debug("===============================");
2257 media_info_get_title(media, &s_value);
2258 content_debug("Title : %s", s_value);
2262 ret = media_info_get_book(media, &book);
2263 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2264 media_info_destroy(media);
2268 ret = book_meta_get_author(book, &s_value);
2269 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
2270 content_debug("Author : %s", s_value);
2275 ret = book_meta_get_date(book, &s_value);
2276 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
2277 content_debug("Date : %s", s_value);
2282 content_debug("===============================");
2283 ret = book_meta_destroy(book);
2284 if (ret != MEDIA_CONTENT_ERROR_NONE)
2285 content_error("book_meta_destroy failed");
2287 ret = media_info_destroy(media);
2288 if (ret != MEDIA_CONTENT_ERROR_NONE)
2289 content_error("media_info_destroy failed");
2291 g_free(book_path_list[i]);
2294 ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
2295 content_debug("Search Time [%lld]", ms_time);
2297 g_free(book_path_list);
2301 int test_disconnect_database(void)
2303 int ret = MEDIA_CONTENT_ERROR_NONE;
2304 content_debug("\n============DB Disconnection Test============\n\n");
2306 ret = media_content_disconnect();
2308 if (ret == MEDIA_CONTENT_ERROR_NONE)
2309 content_debug("disconnection is success");
2311 content_error("disconnection is failed");
2316 int test_request_update_db(void)
2318 int ret = MEDIA_CONTENT_ERROR_NONE;
2319 media_info_h media = NULL;
2320 bool favorite = FALSE;
2322 ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2323 if (ret != MEDIA_CONTENT_ERROR_NONE)
2324 content_error("media_info_get_media_from_db failed: %d", ret);
2326 ret = media_info_set_favorite(media, TRUE);
2327 if (ret != MEDIA_CONTENT_ERROR_NONE)
2328 content_error("media_info_set_favorite failed: %d", ret);
2330 ret = media_info_update_to_db(media);
2331 if (ret == MEDIA_CONTENT_ERROR_NONE)
2332 content_debug("media_info_update_to_db is success");
2334 content_error("media_info_update_to_db is failed");
2337 media_info_destroy(media);
2339 /*get the updated value*/
2340 ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2341 if (ret != MEDIA_CONTENT_ERROR_NONE)
2342 content_error("media_info_get_media_from_db failed: %d", ret);
2344 ret = media_info_get_favorite(media, &favorite);
2345 if (ret != MEDIA_CONTENT_ERROR_NONE)
2346 content_error("media_info_get_favorite failed: %d", ret);
2348 content_debug("favorite [%d]", favorite);
2350 ret = media_info_destroy(media);
2355 static int g_total_photo_size = 0;
2356 static int g_total_video_size = 0;
2357 static int g_total_mp3_size = 0;
2358 static int g_total_voice_memo_size = 0;
2360 bool dft_cb(media_info_h media, void *user_data)
2362 unsigned long long file_size = 0;
2363 media_content_type_e media_type = -1;
2364 char *mime_type = NULL;
2365 int ret = MEDIA_CONTENT_ERROR_NONE;
2370 ret = media_info_get_media_type(media, &media_type);
2371 if (ret != MEDIA_CONTENT_ERROR_NONE)
2372 content_error("media_info_get_media_type failed: %d", ret);
2373 ret = media_info_get_size(media, &file_size);
2374 if (ret != MEDIA_CONTENT_ERROR_NONE)
2375 content_error("media_info_get_size failed: %d", ret);
2376 ret = media_info_get_mime_type(media, &mime_type);
2377 if (ret != MEDIA_CONTENT_ERROR_NONE)
2378 content_error("media_info_get_mime_type failed: %d", ret);
2380 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
2381 g_total_photo_size += file_size;
2382 else if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
2383 g_total_video_size += file_size;
2384 else if (media_type == MEDIA_CONTENT_TYPE_SOUND)
2385 g_total_voice_memo_size += file_size;
2386 else if (media_type == MEDIA_CONTENT_TYPE_MUSIC) {
2387 if ((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
2388 g_total_mp3_size += file_size;
2390 g_total_voice_memo_size += file_size;
2392 content_debug("invalid media_type");
2394 SAFE_FREE(mime_type);
2402 int ret = MEDIA_CONTENT_ERROR_NONE;
2403 content_debug("\n============DFT_test============\n\n");
2405 filter_h filter = NULL;
2408 /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
2410 ret = media_filter_create(&filter);
2413 content_debug("[Internal Memory]\n");
2414 /*1. Photo ============================================================*/
2415 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2418 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2419 content_debug("Photo count = [%d]\n", media_cnt);
2422 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2423 content_debug("Photo size = [%d]\n", g_total_photo_size);
2425 /*2. Video ============================================================*/
2426 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2429 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2430 content_debug("Video count = [%d]\n", media_cnt);
2433 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2434 content_debug("Video size = [%d]\n", g_total_video_size);
2436 /*3. MP3 ============================================================*/
2437 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2440 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2441 content_debug("MP3 count = [%d]\n", media_cnt);
2444 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2445 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2447 /*4. Voice Memo ============================================================*/
2448 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
2450 /*Get Voice Memo Count*/
2451 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2452 content_debug("Voice Memo count = [%d]\n", media_cnt);
2454 /*Get Voice Memo Size*/
2455 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2456 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2458 g_total_photo_size = 0;
2459 g_total_video_size = 0;
2460 g_total_mp3_size = 0;
2461 g_total_voice_memo_size = 0;
2464 content_debug("\n[External Memory]\n");
2465 /*1. Photo ============================================================*/
2466 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2469 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2470 content_debug("Photo count = [%d]\n", media_cnt);
2473 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2474 content_debug("Photo size = [%d]\n", g_total_photo_size);
2476 /*2. Video ============================================================*/
2477 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2480 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2481 content_debug("Video count = [%d]\n", media_cnt);
2484 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2485 content_debug("Video size = [%d]\n", g_total_video_size);
2487 /*3. MP3 ============================================================*/
2488 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2491 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2492 content_debug("MP3 count = [%d]\n", media_cnt);
2495 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2496 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2498 /*4. Voice Memo ============================================================*/
2499 ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
2501 /*Get Voice Memo Count*/
2502 ret = media_info_get_media_count_from_db(filter, &media_cnt);
2503 content_debug("Voice Memo count = [%d]\n", media_cnt);
2505 /*Get Voice Memo Size*/
2506 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2507 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2508 ret = media_filter_destroy(filter);
2513 void insert_batch_cb(media_content_error_e error, void * user_data)
2515 content_debug("media_info_insert_batch_to_db completed!\n");
2518 int test_batch_operations()
2522 char *file_list[10];
2524 for (i = 0; i < 10; i++) {
2525 file_list[i] = g_strdup_printf("%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), i+1);
2526 content_debug("File : %s\n", file_list[i]);
2529 ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL);
2530 if (ret != MEDIA_CONTENT_ERROR_NONE)
2531 content_error("media_info_insert_batch_to_db failed : %d\n", ret);
2533 for (i = 0; i < 10; i++)
2534 g_free(file_list[i]);
2539 void _scan_cb(media_content_error_e err, void *user_data)
2541 content_debug("scan callback is called : %d\n", err);
2542 g_main_loop_quit(g_loop);
2547 int test_scan_file()
2551 const char *file_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2552 ret = media_content_scan_file(file_path);
2553 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2554 content_error("Fail to media_content_scan_file : %d", ret);
2561 gboolean test_scan_dir_start(gpointer data)
2565 const char *dir_path = tzplatform_getenv(TZ_USER_CONTENT);
2567 ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL);
2569 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2570 content_error("Fail to test_scan_dir_start : %d", ret);
2577 gboolean cancel_scan_dir_start(gpointer data)
2579 int ret = MEDIA_CONTENT_ERROR_NONE;
2581 const char *dir_path = tzplatform_getenv(TZ_USER_IMAGES);
2583 ret = media_content_cancel_scan_folder(dir_path);
2585 if (ret == MEDIA_CONTENT_ERROR_NONE)
2586 content_debug("media_content_cancel_scan_folder is success");
2588 content_error("media_content_cancel_scan_folder is failed");
2593 int test_scan_dir(int cancel)
2595 GSource *source = NULL;
2596 GMainContext *context = NULL;
2598 g_loop = g_main_loop_new(NULL, FALSE);
2599 context = g_main_loop_get_context(g_loop);
2600 source = g_idle_source_new();
2601 g_source_set_callback(source, test_scan_dir_start, NULL, NULL);
2602 g_source_attach(source, context);
2605 GSource *cancel_src = NULL;
2606 cancel_src = g_idle_source_new();
2607 g_source_set_callback(cancel_src, cancel_scan_dir_start, NULL, NULL);
2608 g_source_attach(cancel_src, context);
2611 g_main_loop_run(g_loop);
2612 g_main_loop_unref(g_loop);
2617 void _noti_cb(media_content_error_e error,
2619 media_content_db_update_item_type_e update_item,
2620 media_content_db_update_type_e update_type,
2621 media_content_type_e media_type,
2628 content_debug("noti success! : %d\n", error);
2630 content_debug("error occurred! : %d\n", error);
2632 content_debug("Noti from PID(%d)\n", pid);
2634 if (update_item == MEDIA_ITEM_FILE)
2635 content_debug("Noti item : MEDIA_ITEM_FILE\n");
2636 else if (update_item == MEDIA_ITEM_DIRECTORY)
2637 content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n");
2639 if (update_type == MEDIA_CONTENT_INSERT)
2640 content_debug("Noti type : MEDIA_CONTENT_INSERT\n");
2641 else if (update_type == MEDIA_CONTENT_DELETE)
2642 content_debug("Noti type : MEDIA_CONTENT_DELETE\n");
2643 else if (update_type == MEDIA_CONTENT_UPDATE)
2644 content_debug("Noti type : MEDIA_CONTENT_UPDATE\n");
2646 content_debug("content type : %d\n", media_type);
2649 content_debug("path : %s\n", path);
2651 content_debug("path not\n");
2654 content_debug("uuid : %s\n", uuid);
2656 content_debug("uuid not\n");
2659 content_debug("mime_type : %s\n", mime_type);
2661 content_debug("mime not\n");
2663 if (user_data) content_debug("String : %s\n", (char *)user_data);
2668 void _noti_cb_2(media_content_error_e error,
2670 media_content_db_update_item_type_e update_item,
2671 media_content_db_update_type_e update_type,
2672 media_content_type_e media_type,
2679 content_debug("noti_2 success! : %d\n", error);
2681 content_debug("error occurred! : %d\n", error);
2683 content_debug("Noti_2 from PID(%d)\n", pid);
2685 g_main_loop_quit(g_loop);
2689 static media_content_noti_h noti_h;
2690 static media_content_noti_h noti_h_2;
2692 gboolean _send_noti_operations(gpointer data)
2694 int ret = MEDIA_CONTENT_ERROR_NONE;
2696 /* First of all, noti subscription */
2697 char *user_str = strdup("hi");
2698 media_content_add_db_updated_cb(_noti_cb, (void*)user_str, ¬i_h);
2699 media_content_add_db_updated_cb(_noti_cb_2, (void*)user_str, ¬i_h_2);
2701 /* media_info_insert_to_db */
2702 media_info_h media_item = NULL;
2703 const char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2705 ret = media_info_insert_to_db(path, &media_item);
2706 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2707 content_error("media_info_insert_to_db failed : %d", ret);
2708 media_info_destroy(media_item);
2712 content_debug("media_info_insert_to_db success");
2714 media_content_remove_db_updated_cb(noti_h);
2716 /* media_info_update_to_db */
2717 ret = media_info_update_to_db(media_item);
2718 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2719 content_error("media_info_update_to_db failed : %d\n", ret);
2720 media_info_destroy(media_item);
2724 media_info_destroy(media_item);
2731 int ret = MEDIA_CONTENT_ERROR_NONE;
2732 GSource *source = NULL;
2733 GMainContext *context = NULL;
2735 g_loop = g_main_loop_new(NULL, FALSE);
2736 context = g_main_loop_get_context(g_loop);
2737 source = g_idle_source_new();
2738 g_source_set_callback(source, _send_noti_operations, NULL, NULL);
2739 g_source_attach(source, context);
2741 g_main_loop_run(g_loop);
2742 g_main_loop_unref(g_loop);
2744 test_filter_destroy();
2745 media_content_remove_db_updated_cb(noti_h_2);
2750 bool media_face_test_cb(media_face_h face, void *user_data)
2752 get_face_meta(face);
2754 if (user_data != NULL) {
2755 media_face_h new_face = NULL;
2756 media_face_clone(&new_face, face);
2758 GList **list = (GList**)user_data;
2759 *list = g_list_append(*list, new_face);
2767 int ret = MEDIA_CONTENT_ERROR_NONE;
2768 filter_h filter = NULL;
2769 GList *all_item_list = NULL;
2772 ret = media_filter_create(&filter);
2773 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
2775 ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", MEDIA_CONTENT_COLLATE_DEFAULT);
2776 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2777 media_filter_destroy(filter);
2778 content_error("Fail to set condition");
2782 ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
2783 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2784 content_error("media_info_foreach_media_from_db failed: %d", ret);
2785 media_filter_destroy(filter);
2789 for (i = 0; i < g_list_length(all_item_list); i++) {
2790 media_info_h media_handle = NULL;
2791 char *media_id = NULL;
2794 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
2796 ret = media_info_get_media_id(media_handle, &media_id);
2797 if (ret != MEDIA_CONTENT_ERROR_NONE)
2798 content_error("media_info_get_media_id failed: %d", ret);
2800 ret = media_info_get_face_count_from_db(media_id, filter, &face_count);
2801 if (ret != MEDIA_CONTENT_ERROR_NONE)
2802 content_error("media_info_get_face_count_from_db failed: %d", ret);
2804 content_error("media_id [%s] face_count [%d]", media_id, face_count);
2806 ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, NULL);
2807 if (ret != MEDIA_CONTENT_ERROR_NONE)
2808 content_error("media_info_foreach_face_from_db failed: %d", ret);
2810 media_info_destroy(media_handle);
2813 media_filter_destroy(filter);
2818 int test_face_add_del(void)
2820 int ret = MEDIA_CONTENT_ERROR_NONE;
2821 char *media_id = "ecca7366-e085-41d8-a12b-cbdfc2b9c5fc";
2824 media_face_h face = NULL;
2826 char *face_tag = "test_face_tag";
2828 ret = media_face_create(media_id, &face);
2829 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_face_create");
2831 ret = media_face_set_face_rect(face, 10, 12, 50, 100);
2832 if (ret != MEDIA_CONTENT_ERROR_NONE)
2833 content_error("media_face_set_face_rect failed: %d", ret);
2835 ret = media_face_set_orientation(face, 5);
2836 if (ret != MEDIA_CONTENT_ERROR_NONE)
2837 content_error("media_face_set_orientation failed: %d", ret);
2839 ret = media_face_set_tag(face, face_tag);
2840 if (ret != MEDIA_CONTENT_ERROR_NONE)
2841 content_error("media_face_set_tag failed: %d", ret);
2843 ret = media_face_insert_to_db(face);
2844 if (ret != MEDIA_CONTENT_ERROR_NONE)
2845 content_error("media_face_insert_to_db failed: %d", ret);
2847 ret = media_face_destroy(face);
2848 if (ret != MEDIA_CONTENT_ERROR_NONE)
2849 content_error("media_face_destroy failed: %d", ret);
2852 GList *all_item_list = NULL;
2853 filter_h filter = NULL;
2854 ret = media_filter_create(&filter);
2855 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
2857 ret = media_filter_set_condition(filter, "MEDIA_FACE_TAG IS NOT NULL", MEDIA_CONTENT_COLLATE_DEFAULT);
2858 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2859 media_filter_destroy(filter);
2860 content_error("Fail to set condition");
2864 ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, &all_item_list);
2866 if (g_list_length(all_item_list) > 0) {
2867 media_face_h face_handle = NULL;
2868 face_handle = (media_face_h)g_list_nth_data(all_item_list, 0);
2870 ret = media_face_set_face_rect(face_handle, 20, 22, 70, 70);
2871 if (ret != MEDIA_CONTENT_ERROR_NONE)
2872 content_error("media_face_set_face_rect failed: %d", ret);
2873 ret = media_face_set_orientation(face_handle, 3);
2874 if (ret != MEDIA_CONTENT_ERROR_NONE)
2875 content_error("media_face_set_orientation failed: %d", ret);
2876 ret = media_face_set_tag(face_handle, NULL);
2877 if (ret != MEDIA_CONTENT_ERROR_NONE)
2878 content_error("media_face_set_tag failed: %d", ret);
2879 ret = media_face_update_to_db(face_handle);
2880 if (ret != MEDIA_CONTENT_ERROR_NONE)
2881 content_error("media_face_update_to_db failed: %d", ret);
2883 media_face_destroy(face_handle);
2886 media_filter_destroy(filter);
2889 char *face_id = "5e58a3a8-f0b2-4c29-b799-b49a70dc2313";
2892 ret = media_face_delete_from_db(face_id);
2897 #ifdef _USE_TVPD_MODE
2898 filter_h g_tv_filter = NULL;
2900 int test_tv_filter_create(void)
2902 content_debug("\n============Filter Create============\n\n");
2904 int ret = MEDIA_CONTENT_ERROR_NONE;
2906 ret = media_filter_create(&g_tv_filter);
2908 ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
2910 ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
2915 int test_tv_filter_destroy(void)
2917 content_debug("\n============Filter Destroy============\n\n");
2919 int ret = MEDIA_CONTENT_ERROR_NONE;
2921 ret = media_filter_destroy(g_tv_filter);
2926 bool pvr_item_cb(media_pvr_h pvr, void *user_data)
2928 int ret = MEDIA_CONTENT_ERROR_NONE;
2929 char *c_value = NULL;
2931 bool b_value = false;
2932 unsigned long long l_value = 0;
2935 content_debug("NO Item");
2939 ret = media_pvr_get_media_id(pvr, &c_value);
2940 if (ret != MEDIA_CONTENT_ERROR_NONE)
2941 content_error("Fail to media_pvr_get_media_id");
2942 content_debug("media_id [%s]", c_value);
2945 ret = media_pvr_get_channel_name(pvr, &c_value);
2946 if (ret != MEDIA_CONTENT_ERROR_NONE)
2947 content_error("Fail to media_pvr_get_channel_name");
2948 content_debug("channel_name [%s]", c_value);
2951 ret = media_pvr_get_program_title(pvr, &c_value);
2952 if (ret != MEDIA_CONTENT_ERROR_NONE)
2953 content_error("Fail to media_pvr_get_program_title");
2954 content_debug("program_title [%s]", c_value);
2957 ret = media_pvr_get_program_crid(pvr, &c_value);
2958 if (ret != MEDIA_CONTENT_ERROR_NONE)
2959 content_error("Fail to media_pvr_get_program_crid");
2960 content_debug("program_crid [%s]", c_value);
2963 ret = media_pvr_get_guidance(pvr, &c_value);
2964 if (ret != MEDIA_CONTENT_ERROR_NONE)
2965 content_error("Fail to media_pvr_get_guidance");
2966 content_debug("guidance [%s]", c_value);
2969 ret = media_pvr_get_synopsis(pvr, &c_value);
2970 if (ret != MEDIA_CONTENT_ERROR_NONE)
2971 content_error("Fail to media_pvr_get_synopsis");
2972 content_debug("synopsis [%s]", c_value);
2975 ret = media_pvr_get_genre(pvr, &c_value);
2976 if (ret != MEDIA_CONTENT_ERROR_NONE)
2977 content_error("Fail to media_pvr_get_synopsis");
2978 content_debug("genre [%s]", c_value);
2981 ret = media_pvr_get_language(pvr, &c_value);
2982 if (ret != MEDIA_CONTENT_ERROR_NONE)
2983 content_error("Fail to media_pvr_get_language");
2984 content_debug("language [%s]", c_value);
2987 ret = media_pvr_get_path(pvr, &c_value);
2988 if (ret != MEDIA_CONTENT_ERROR_NONE)
2989 content_error("Fail to media_pvr_get_path");
2990 content_debug("path [%s]", c_value);
2993 ret = media_pvr_get_storage_id(pvr, &c_value);
2994 if (ret != MEDIA_CONTENT_ERROR_NONE)
2995 content_error("Fail to media_pvr_get_storage_id");
2996 content_debug("storage_id [%s]", c_value);
2999 ret = media_pvr_get_size(pvr, &l_value);
3000 if (ret != MEDIA_CONTENT_ERROR_NONE)
3001 content_error("Fail to media_pvr_get_size");
3002 content_debug("size [%lld]", l_value);
3004 ret = media_pvr_get_timezone(pvr, &i_value);
3005 if (ret != MEDIA_CONTENT_ERROR_NONE)
3006 content_error("Fail to media_pvr_get_timezone");
3007 content_debug("timezone [%d]", i_value);
3009 ret = media_pvr_get_ptc(pvr, &i_value);
3010 if (ret != MEDIA_CONTENT_ERROR_NONE)
3011 content_error("Fail to media_pvr_get_ptc");
3012 content_debug("ptc [%d]", i_value);
3014 ret = media_pvr_get_major(pvr, &i_value);
3015 if (ret != MEDIA_CONTENT_ERROR_NONE)
3016 content_error("Fail to media_pvr_get_major");
3017 content_debug("[%d]", i_value);
3019 ret = media_pvr_get_minor(pvr, &i_value);
3020 if (ret != MEDIA_CONTENT_ERROR_NONE)
3021 content_error("Fail to media_pvr_get_minor");
3022 content_debug("minor [%d]", i_value);
3024 ret = media_pvr_get_channel_type(pvr, &i_value);
3025 if (ret != MEDIA_CONTENT_ERROR_NONE)
3026 content_error("Fail to media_pvr_get_channel_type");
3027 content_debug("channel_type [%d]", i_value);
3029 ret = media_pvr_get_program_num(pvr, &i_value);
3030 if (ret != MEDIA_CONTENT_ERROR_NONE)
3031 content_error("Fail to media_pvr_get_program_num");
3032 content_debug("program_num [%d]", i_value);
3034 unsigned int ui_value = 0;
3035 ret = media_pvr_get_service_profile(pvr, &ui_value);
3036 if (ret != MEDIA_CONTENT_ERROR_NONE)
3037 content_error("Fail to media_pvr_get_service_profile");
3038 content_debug("service_profile [%u]", ui_value);
3040 ret = media_pvr_get_duration(pvr, &i_value);
3041 if (ret != MEDIA_CONTENT_ERROR_NONE)
3042 content_error("Fail to media_pvr_get_duration");
3043 content_debug("duration [%d]", i_value);
3045 ret = media_pvr_get_embargo_time(pvr, &i_value);
3046 if (ret != MEDIA_CONTENT_ERROR_NONE)
3047 content_error("Fail to media_pvr_get_embargo_time");
3048 content_debug("embargo_time [%d]", i_value);
3050 ret = media_pvr_get_expiry_time(pvr, &i_value);
3051 if (ret != MEDIA_CONTENT_ERROR_NONE)
3052 content_error("Fail to media_pvr_get_expiry_time");
3053 content_debug("expiry_time [%d]", i_value);
3055 ret = media_pvr_get_parental_rating(pvr, &i_value);
3056 if (ret != MEDIA_CONTENT_ERROR_NONE)
3057 content_error("Fail to media_pvr_get_parental_rating");
3058 content_debug("parental_rating [%d]", i_value);
3060 ret = media_pvr_get_start_time(pvr, &i_value);
3061 if (ret != MEDIA_CONTENT_ERROR_NONE)
3062 content_error("Fail to media_pvr_get_start_time");
3063 content_debug("start_time [%d]", i_value);
3065 ret = media_pvr_get_program_start_time(pvr, &i_value);
3066 if (ret != MEDIA_CONTENT_ERROR_NONE)
3067 content_error("Fail to media_pvr_get_program_start_time");
3068 content_debug("program_start_time [%d]", i_value);
3070 ret = media_pvr_get_program_end_time(pvr, &i_value);
3071 if (ret != MEDIA_CONTENT_ERROR_NONE)
3072 content_error("Fail to media_pvr_get_program_end_time");
3073 content_debug("program_end_time [%d]", i_value);
3075 ret = media_pvr_get_program_date(pvr, &i_value);
3076 if (ret != MEDIA_CONTENT_ERROR_NONE)
3077 content_error("Fail to media_pvr_get_program_date");
3078 content_debug("program_date [%d]", i_value);
3080 ret = media_pvr_get_timer_record(pvr, &b_value);
3081 if (ret != MEDIA_CONTENT_ERROR_NONE)
3082 content_error("Fail to media_pvr_get_timer_record");
3083 content_debug("timer_record [%d]", b_value);
3085 ret = media_pvr_get_series_record(pvr, &b_value);
3086 if (ret != MEDIA_CONTENT_ERROR_NONE)
3087 content_error("Fail to media_pvr_get_series_record");
3088 content_debug("series_record [%d]", b_value);
3090 ret = media_pvr_get_hd(pvr, &i_value);
3091 if (ret != MEDIA_CONTENT_ERROR_NONE)
3092 content_error("Fail to media_pvr_get_hd");
3093 content_debug("hd [%d]", i_value);
3095 ret = media_pvr_get_subtitle(pvr, &b_value);
3096 if (ret != MEDIA_CONTENT_ERROR_NONE)
3097 content_error("Fail to media_pvr_get_subtitle");
3098 content_debug("subtitle [%d]", b_value);
3100 ret = media_pvr_get_ttx(pvr, &b_value);
3101 if (ret != MEDIA_CONTENT_ERROR_NONE)
3102 content_error("Fail to media_pvr_get_ttx");
3103 content_debug("ttx [%d]", b_value);
3105 ret = media_pvr_get_ad(pvr, &b_value);
3106 if (ret != MEDIA_CONTENT_ERROR_NONE)
3107 content_error("Fail to media_pvr_get_ad");
3108 content_debug("ad [%d]", b_value);
3110 ret = media_pvr_get_hard_of_hearing_radio(pvr, &b_value);
3111 if (ret != MEDIA_CONTENT_ERROR_NONE)
3112 content_error("Fail to media_pvr_get_hard_of_hearing_radio");
3113 content_debug("hard_of_hearing_radio [%d]", b_value);
3115 ret = media_pvr_get_data_service(pvr, &b_value);
3116 if (ret != MEDIA_CONTENT_ERROR_NONE)
3117 content_error("Fail to media_pvr_get_data_service");
3118 content_debug("data_service [%d]", b_value);
3120 ret = media_pvr_get_content_lock(pvr, &b_value);
3121 if (ret != MEDIA_CONTENT_ERROR_NONE)
3122 content_error("Fail to media_pvr_get_content_lock");
3123 content_debug("content_lock [%d]", b_value);
3125 ret = media_pvr_get_content_watch(pvr, &b_value);
3126 if (ret != MEDIA_CONTENT_ERROR_NONE)
3127 content_error("Fail to media_pvr_get_content_watch");
3128 content_debug("content_watch [%d]", b_value);
3130 ret = media_pvr_get_has_audio_only(pvr, &b_value);
3131 if (ret != MEDIA_CONTENT_ERROR_NONE)
3132 content_error("Fail to media_pvr_get_has_audio_only");
3133 content_debug("has_audio_only [%d]", b_value);
3135 ret = media_pvr_get_is_local_record(pvr, &b_value);
3136 if (ret != MEDIA_CONTENT_ERROR_NONE)
3137 content_error("Fail to media_pvr_get_is_local_record");
3138 content_debug("is_local_record [%d]", b_value);
3140 ret = media_pvr_get_resolution(pvr, (media_pvr_resolution_e*)&i_value);
3141 if (ret != MEDIA_CONTENT_ERROR_NONE)
3142 content_error("Fail to media_pvr_get_resolution");
3143 content_debug("resolution [%d]", i_value);
3145 ret = media_pvr_get_aspectratio(pvr, (media_pvr_aspectratio_e*)&i_value);
3146 if (ret != MEDIA_CONTENT_ERROR_NONE)
3147 content_error("Fail to media_pvr_get_aspectratio");
3148 content_debug("aspectratio [%d]", i_value);
3150 ret = media_pvr_get_highlight(pvr, &b_value);
3151 if (ret != MEDIA_CONTENT_ERROR_NONE)
3152 content_error("Fail to media_pvr_get_highlight");
3153 content_debug("highlight [%d]", b_value);
3161 int ret = MEDIA_CONTENT_ERROR_NONE;
3162 int media_count = 0;
3164 content_debug("\n============PVR Test============\n\n");
3166 test_tv_filter_create();
3168 ret = media_pvr_get_media_count_from_db(g_tv_filter, &media_count);
3169 if (ret != MEDIA_CONTENT_ERROR_NONE)
3170 content_error("media_pvr_get_media_count_from_db failed: %d", ret);
3172 content_debug("media_count : [%d]", media_count);
3174 ret = media_pvr_foreach_media_from_db(g_tv_filter, pvr_item_cb, NULL);
3175 if (ret != MEDIA_CONTENT_ERROR_NONE)
3176 content_error("media_pvr_foreach_media_from_db is failed");
3178 test_tv_filter_destroy();
3183 int test_pvr_update_db(void)
3185 int ret = MEDIA_CONTENT_ERROR_NONE;
3186 media_pvr_h pvr = NULL;
3188 ret = media_pvr_get_pvr_from_db("ff9b5a9a-a7b4-47f4-8255-84e007e25f13", &pvr);
3189 if (ret != MEDIA_CONTENT_ERROR_NONE)
3190 content_error("media_pvr_get_pvr_from_db failed: %d", ret);
3192 ret = media_pvr_set_content_lock(pvr, TRUE);
3193 if (ret != MEDIA_CONTENT_ERROR_NONE)
3194 content_error("Fail to media_pvr_set_content_lock");
3196 ret = media_pvr_set_content_watch(pvr, TRUE);
3197 if (ret != MEDIA_CONTENT_ERROR_NONE)
3198 content_error("Fail to media_pvr_set_content_watch");
3200 ret = media_pvr_set_program_title(pvr, "TEST TITLE");
3201 if (ret != MEDIA_CONTENT_ERROR_NONE)
3202 content_error("Fail to media_pvr_set_program_title");
3204 ret = media_pvr_set_highlight(pvr, TRUE);
3205 if (ret != MEDIA_CONTENT_ERROR_NONE)
3206 content_error("Fail to media_pvr_set_highlight");
3208 ret = media_pvr_update_to_db(pvr);
3209 if (ret != MEDIA_CONTENT_ERROR_NONE)
3210 content_error("Fail to media_pvr_update_to_db");
3213 media_pvr_destroy(pvr);
3219 int main(int argc, char *argv[])
3221 int ret = MEDIA_CONTENT_ERROR_NONE;
3223 content_debug("--- content manager test start ---\n\n");
3225 ret = test_connect_database();
3226 if (ret != MEDIA_CONTENT_ERROR_NONE)
3227 return MEDIA_CONTENT_ERROR_NONE;
3228 #ifdef _USE_TVPD_MODE
3231 test_pvr_update_db();
3238 ret = test_ebook_text_finder(argv[1]);
3239 if (ret != MEDIA_CONTENT_ERROR_NONE)
3243 ret = test_start_face_detection(FALSE);
3244 if (ret != MEDIA_CONTENT_ERROR_NONE)
3248 if (ret != MEDIA_CONTENT_ERROR_NONE)
3251 ret = test_gallery_scenario();
3252 if (ret != MEDIA_CONTENT_ERROR_NONE)
3255 ret = test_get_all_music_files();
3256 if (ret != MEDIA_CONTENT_ERROR_NONE)
3259 ret = test_media_info_operation();
3260 if (ret != MEDIA_CONTENT_ERROR_NONE)
3263 ret = test_folder_operation();
3264 if (ret != MEDIA_CONTENT_ERROR_NONE)
3267 ret = test_playlist_operation();
3268 if (ret != MEDIA_CONTENT_ERROR_NONE)
3271 ret = test_tag_operation();
3272 if (ret != MEDIA_CONTENT_ERROR_NONE)
3275 ret = test_bookmark_operation();
3276 if (ret != MEDIA_CONTENT_ERROR_NONE)
3279 ret = test_album_list();
3280 if (ret != MEDIA_CONTENT_ERROR_NONE)
3283 ret = test_group_operation();
3284 if (ret != MEDIA_CONTENT_ERROR_NONE)
3287 ret = test_update_operation();
3288 if (ret != MEDIA_CONTENT_ERROR_NONE)
3291 ret = test_insert();
3292 if (ret != MEDIA_CONTENT_ERROR_NONE)
3296 if (ret != MEDIA_CONTENT_ERROR_NONE)
3299 ret = test_create_thumbnail(TRUE);
3300 if (ret != MEDIA_CONTENT_ERROR_NONE)
3303 ret = test_extrace_face(TRUE);
3304 if (ret != MEDIA_CONTENT_ERROR_NONE)
3307 ret = test_request_update_db();
3308 if (ret != MEDIA_CONTENT_ERROR_NONE)
3312 if (ret != MEDIA_CONTENT_ERROR_NONE)
3315 ret = test_batch_operations();
3316 if (ret != MEDIA_CONTENT_ERROR_NONE)
3317 return MEDIA_CONTENT_ERROR_NONE;
3319 ret = test_scan_file();
3320 if (ret != MEDIA_CONTENT_ERROR_NONE)
3321 return MEDIA_CONTENT_ERROR_NONE;
3323 ret = test_scan_dir(true);
3324 if (ret != MEDIA_CONTENT_ERROR_NONE)
3325 return MEDIA_CONTENT_ERROR_NONE;
3328 if (ret != MEDIA_CONTENT_ERROR_NONE)
3329 return MEDIA_CONTENT_ERROR_NONE;
3332 if (ret != MEDIA_CONTENT_ERROR_NONE)
3333 return MEDIA_CONTENT_ERROR_NONE;
3335 ret = test_face_add_del();
3336 if (ret != MEDIA_CONTENT_ERROR_NONE)
3337 return MEDIA_CONTENT_ERROR_NONE;
3339 ret = test_playlist_operation_v2();
3340 if (ret != MEDIA_CONTENT_ERROR_NONE)
3341 return MEDIA_CONTENT_ERROR_NONE;
3343 ret = test_bookmark_operation_v2();
3344 if (ret != MEDIA_CONTENT_ERROR_NONE)
3345 return MEDIA_CONTENT_ERROR_NONE;
3347 ret = test_tag_operation_v2();
3348 if (ret != MEDIA_CONTENT_ERROR_NONE)
3349 return MEDIA_CONTENT_ERROR_NONE;
3352 ret = test_disconnect_database();
3353 if (ret != MEDIA_CONTENT_ERROR_NONE)
3356 content_debug("--- content manager test end ---\n");