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>
24 #include <tzplatform_config.h>
25 #include <media_content_internal.h>
28 static filter_h g_filter = NULL;
30 static GMainLoop *g_loop = NULL;
32 #define test_audio_id "3304285f-1070-41af-8b4e-f0086cc768f3"
33 #define test_video_id "53c43e7e-53d2-4194-80a6-55d5dcde0def"
34 #define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197"
35 #define SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
37 static void get_audio_meta(media_info_h media)
39 audio_meta_h audio = NULL;
42 content_debug("=== audio meta ===");
43 if (media_info_get_audio(media, &audio) != MEDIA_CONTENT_ERROR_NONE)
46 if (audio_meta_get_media_id(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
47 content_debug("audio_id : [%s]", c_value);
51 if (audio_meta_get_album(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
52 content_debug("album : [%s]", c_value);
56 if (audio_meta_get_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
57 content_debug("artist : [%s]", c_value);
61 if (audio_meta_get_album_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
62 content_debug("album artist : [%s]", c_value);
66 if (audio_meta_get_genre(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
67 content_debug("genre : [%s]", c_value);
71 if (audio_meta_get_year(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
72 content_debug("year : [%s]", c_value);
76 if (audio_meta_get_track_num(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
77 content_debug("track number : [%s]", c_value);
81 audio_meta_destroy(audio);
84 static void get_image_meta(media_info_h media)
86 image_meta_h image = NULL;
89 media_content_orientation_e orientation;
91 content_debug("=== image meta ===");
92 if (media_info_get_image(media, &image) != MEDIA_CONTENT_ERROR_NONE)
95 if (image_meta_get_width(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
96 content_debug("width : [%d]", i_value);
98 if (image_meta_get_height(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
99 content_debug("height : [%d]", i_value);
101 if (image_meta_get_orientation(image, &orientation) == MEDIA_CONTENT_ERROR_NONE)
102 content_debug("orientation : [%d]", orientation);
104 if (image_meta_get_date_taken(image, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
105 content_debug("datetaken : [%s]", c_value);
109 image_meta_destroy(image);
112 static void get_book_meta(media_info_h media)
114 book_meta_h book = NULL;
115 char *c_value = NULL;
117 content_debug("=== book meta ===");
118 if (media_info_get_book(media, &book) != MEDIA_CONTENT_ERROR_NONE)
121 if (book_meta_get_media_id(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
122 content_debug("media_id : [%s]", c_value);
126 if (book_meta_get_author(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
127 content_debug("author : [%s]", c_value);
131 if (book_meta_get_subject(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
132 content_debug("subject : [%s]", c_value);
136 book_meta_destroy(book);
139 static void get_album_meta(media_album_h album)
141 char *c_value = NULL;
144 content_debug("=== album meta ===");
145 if (media_album_get_album_id(album, &i_value) == MEDIA_CONTENT_ERROR_NONE)
146 content_debug("album id : [%d]", i_value);
148 if (media_album_get_name(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
149 content_debug("album name : [%s]", c_value);
153 if (media_album_get_artist(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
154 content_debug("album artist : [%s]", c_value);
159 static void get_folder_meta(media_folder_h folder, char **folder_id)
161 char *c_value = NULL;
163 content_debug("=== folder meta ===");
164 if (media_folder_get_folder_id(folder, &c_value) != MEDIA_CONTENT_ERROR_NONE) {
165 content_debug("folder_id : %s", c_value);
166 *folder_id = c_value;
169 if (media_folder_get_path(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
170 content_debug("folder_path : %s", c_value);
174 if (media_folder_get_name(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
175 content_debug("folder_name : %s", c_value);
180 static void get_media_meta(media_info_h media)
182 char *c_value = NULL;
184 unsigned long long size = 0;
185 media_content_type_e media_type = 0;
186 #ifdef _USE_TVPD_MODE
190 content_debug("=== media meta ===");
191 if (media_info_get_media_type(media, &media_type) == MEDIA_CONTENT_ERROR_NONE)
192 content_debug("media_type : [%d]", media_type);
194 if (media_info_get_media_id(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
195 content_debug("media_id : [%s]", c_value);
199 if (media_info_get_file_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
200 content_debug("file_path : [%s]", c_value);
204 if (media_info_get_display_name(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
205 content_debug("display_name : [%s]", c_value);
209 if (media_info_get_mime_type(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
210 content_debug("mime_type : [%s]", c_value);
214 if (media_info_get_thumbnail_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
215 content_debug("thumbnail_path : [%s]", c_value);
219 if (media_info_get_size(media, &size) == MEDIA_CONTENT_ERROR_NONE)
220 content_debug("size : [%lld]", size);
222 if (media_info_get_added_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
223 content_debug("added_time : [%ld]", t_value);
225 if (media_info_get_modified_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
226 content_debug("modified_time : [%ld]", t_value);
228 #ifdef _USE_TVPD_MODE
229 if (media_info_get_stitched_state(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
230 content_debug("360 stitched : [%d]", i_value);
233 if (media_type == MEDIA_CONTENT_TYPE_MUSIC)
234 get_audio_meta(media);
236 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
237 get_image_meta(media);
239 if (media_type == MEDIA_CONTENT_TYPE_BOOK)
240 get_book_meta(media);
242 if (media_type == MEDIA_CONTENT_TYPE_OTHERS)
243 content_debug("Other type");
246 bool media_item_cb(media_info_h media, void *user_data)
249 content_debug("NO Item");
253 get_media_meta(media);
258 bool gallery_folder_list_cb(media_folder_h folder, void *user_data)
260 media_folder_h new_folder = NULL;
261 media_folder_clone(&new_folder, folder);
263 GList **list = (GList**)user_data;
264 *list = g_list_append(*list, new_folder);
269 bool gallery_media_item_cb(media_info_h media, void *user_data)
271 media_info_h new_media = NULL;
272 int ret = MEDIA_CONTENT_ERROR_NONE;
274 ret = media_info_clone(&new_media, media);
276 if (ret != MEDIA_CONTENT_ERROR_NONE) {
277 GList **list = (GList**)user_data;
278 *list = g_list_append(*list, new_media);
284 bool folder_list_cb(media_folder_h folder, void *user_data)
287 char *folder_id = NULL;
288 media_folder_h *_folder = (media_folder_h*)user_data;
290 content_debug("===========================");
291 if (folder != NULL) {
293 media_folder_clone(_folder, folder);
295 get_folder_meta(folder, &folder_id);
297 if (media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) {
298 SAFE_FREE(folder_id);
299 content_error("[ERROR] media_folder_get_media_count_from_db is failed");
303 if (media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) {
304 SAFE_FREE(folder_id);
305 content_error("[ERROR] media_folder_foreach_media_from_db is failed");
309 SAFE_FREE(folder_id);
317 bool album_list_cb(media_album_h album, void *user_data)
321 int ret = MEDIA_CONTENT_ERROR_NONE;
324 get_album_meta(album);
325 media_album_get_album_id(album, &album_id);
327 ret = media_album_get_media_count_from_db(album_id, NULL, &media_count);
328 if (ret != MEDIA_CONTENT_ERROR_NONE)
329 content_error("error media_album_get_media_count_from_db : [%d]", ret);
331 content_debug("media_count : [%d]", media_count);
333 ret = media_album_foreach_media_from_db(album_id, NULL, media_item_cb, NULL);
334 if (ret != MEDIA_CONTENT_ERROR_NONE) {
335 content_error("error media_album_foreach_media_from_db : [%d]", ret);
340 content_error("album item not Found!!");
346 bool group_list_cb(const char *group_name, void *user_data)
349 int *idx = user_data;
351 content_debug("group item : [%s] [%d]", group_name, *idx);
353 if (media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
356 content_debug("media_count : [%d]", media_count);
358 if (media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
364 int test_filter_create(void)
366 content_debug("\n============Filter Create============\n\n");
368 int ret = MEDIA_CONTENT_ERROR_NONE;
370 /* Filter for media */
371 const char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
373 ret = media_filter_create(&g_filter);
375 /* Set condition and collate
376 * Condition string : You can make where statement of sql.
377 * Colation : You can use collation when comparing.
378 * Ex) In case of FILE_NAME='Samsung' as condition string,
379 * if you want to compare with NOCASE collation,
380 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
381 * if you want to compare in case-sensitive,
382 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
384 ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
389 int test_filter_destroy(void)
391 content_debug("\n============Filter Create============\n\n");
393 int ret = MEDIA_CONTENT_ERROR_NONE;
395 ret = media_filter_destroy(g_filter);
400 int test_connect_database(void)
402 int ret = MEDIA_CONTENT_ERROR_NONE;
404 content_debug("\n============DB Connection Test============\n\n");
406 ret = media_content_connect();
408 if (ret == MEDIA_CONTENT_ERROR_NONE)
409 content_debug("connection is success\n\n");
411 content_error("connection is failed\n\n");
416 int test_gallery_scenario(void)
418 int ret = MEDIA_CONTENT_ERROR_NONE;
420 filter_h filter = NULL;
423 GList *folder_list = NULL;
424 media_folder_h folder_handle = NULL;
426 /* First, Get folder list */
427 ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
428 if (ret != MEDIA_CONTENT_ERROR_NONE) {
429 content_error("media_folder_foreach_folder_from_db failed: %d", ret);
432 content_debug("media_folder_foreach_folder_from_db success!!");
433 char *folder_id = NULL;
435 for (i = 0; i < g_list_length(folder_list); i++) {
436 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
438 get_folder_meta(folder_handle, &folder_id);
440 ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
441 SAFE_FREE(folder_id);
442 if (ret != MEDIA_CONTENT_ERROR_NONE) {
443 content_error("media_folder_get_media_count_from_db failed: %d", ret);
446 content_debug("media count [%d] : %d", i, count);
451 /* To check performance */
452 struct timeval start, end;
453 gettimeofday(&start, NULL);
455 /* Second, Get all item list */
456 media_info_h media_handle = NULL;
457 GList *all_item_list = NULL;
459 media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
460 media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
461 ret = media_filter_create(&filter);
462 if (ret != MEDIA_CONTENT_ERROR_NONE) {
463 content_error("Fail to create filter");
466 ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
467 if (ret != MEDIA_CONTENT_ERROR_NONE) {
468 media_filter_destroy(filter);
469 content_error("Fail to set condition");
472 ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
473 if (ret != MEDIA_CONTENT_ERROR_NONE) {
474 media_filter_destroy(filter);
475 content_error("Fail to set order");
479 ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
480 if (ret != MEDIA_CONTENT_ERROR_NONE) {
481 content_error("media_info_foreach_media_from_db failed: %d", ret);
482 media_filter_destroy(filter);
485 content_debug("media_info_foreach_media_from_db success");
487 for (i = 0; i < g_list_length(all_item_list); i++) {
488 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
489 get_media_meta(media_handle);
493 media_filter_destroy(filter);
496 /* To check performance */
497 gettimeofday(&end, NULL);
498 long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
499 content_debug("Time : %ld\n", time);
501 /* Third, Get item list of a folder */
502 GList *item_list = NULL;
504 for (i = 0; i < g_list_length(folder_list); i++) {
506 char *folder_id = NULL;
507 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
509 get_folder_meta(folder_handle, &folder_id);
511 ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
512 SAFE_FREE(folder_id);
514 if (ret != MEDIA_CONTENT_ERROR_NONE) {
515 content_error("media_folder_foreach_media_from_db failed: %d", ret);
518 content_error("media_folder_foreach_media_from_db success!");
520 for (j = 0; j < g_list_length(item_list); j++) {
521 media_handle = (media_info_h)g_list_nth_data(item_list, j);
522 get_media_meta(media_handle);
527 /* Remove folder list */
529 for (i = 0; i < g_list_length(folder_list); i++) {
530 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
531 media_folder_destroy(folder_handle);
534 g_list_free(folder_list);
537 /* Remove all items list */
539 for (i = 0; i < g_list_length(all_item_list); i++) {
540 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
541 ret = media_info_destroy(media_handle);
542 if (ret != MEDIA_CONTENT_ERROR_NONE)
543 content_error("media_info_destroy failed: %d", ret);
546 g_list_free(all_item_list);
549 /* Remove items list */
551 for (i = 0; i < g_list_length(item_list); i++) {
552 media_handle = (media_info_h)g_list_nth_data(item_list, i);
553 ret = media_info_destroy(media_handle);
554 if (ret != MEDIA_CONTENT_ERROR_NONE)
555 content_error("media_info_destroy failed: %d", ret);
558 g_list_free(item_list);
561 return MEDIA_CONTENT_ERROR_NONE;
564 /*Get All Music file. sort by Title and not case sensitive*/
565 int test_get_all_music_files(void)
567 int ret = MEDIA_CONTENT_ERROR_NONE;
572 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
574 ret = media_filter_create(&filter);
575 if (ret != MEDIA_CONTENT_ERROR_NONE) {
576 content_error("Fail to create filter");
579 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED);
580 if (ret != MEDIA_CONTENT_ERROR_NONE) {
581 media_filter_destroy(filter);
582 content_error("Fail to set condition");
585 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED);
586 if (ret != MEDIA_CONTENT_ERROR_NONE) {
587 media_filter_destroy(filter);
588 content_error("Fail to set order");
593 ret = media_info_get_media_count_from_db(filter, &media_count);
594 if (ret != MEDIA_CONTENT_ERROR_NONE) {
595 media_filter_destroy(filter);
596 content_error("Fail to get media count");
600 content_debug("media_count : [%d]", media_count);
602 ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
603 if (ret != MEDIA_CONTENT_ERROR_NONE) {
604 media_filter_destroy(filter);
605 content_error("Fail to get media");
609 ret = media_filter_destroy(filter);
614 int test_media_info_operation(void)
616 int ret = MEDIA_CONTENT_ERROR_NONE;
619 content_debug("\n============Media info Test============\n\n");
621 test_filter_create();
623 ret = media_info_get_media_count_from_db(g_filter, &media_count);
624 if (ret != MEDIA_CONTENT_ERROR_NONE)
625 content_error("media_info_get_media_count_from_db failed: %d", ret);
627 content_debug("media_count : [%d]", media_count);
629 ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
630 if (ret == MEDIA_CONTENT_ERROR_NONE)
631 content_debug("media_info_foreach_media_from_db is success");
633 content_error("media_info_foreach_media_from_db is failed");
635 test_filter_destroy();
640 int test_folder_operation(void)
642 int ret = MEDIA_CONTENT_ERROR_NONE;
643 filter_h filter = NULL;
644 media_folder_h folder = NULL;
645 char *folder_id = NULL;
648 content_debug("\n============Folder Test============\n\n");
650 test_filter_create();
652 ret = media_filter_create(&filter);
653 if (ret != MEDIA_CONTENT_ERROR_NONE) {
654 content_error("[ERROR] media_folder_filter_create is failed");
658 media_filter_set_condition(filter, "MEDIA_TYPE = 0 or MEDIA_TYPE = 1", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
659 media_filter_set_offset(filter, 0, 5);
660 media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
662 ret = media_folder_get_folder_count_from_db(filter, &count);
663 content_debug("Folder count : [%d]", count);
665 ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
667 filter_h m_filter = NULL;
669 ret = media_filter_create(&m_filter);
670 if (ret != MEDIA_CONTENT_ERROR_NONE) {
671 test_filter_destroy();
672 media_filter_destroy(filter);
673 content_error("[ERROR] media_info_filter_create is failed");
677 media_filter_set_condition(m_filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
678 media_filter_set_offset(m_filter, 0, 5);
679 media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
681 ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
682 if (ret != MEDIA_CONTENT_ERROR_NONE)
683 content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret);
685 media_filter_destroy(filter);
686 media_filter_destroy(m_filter);
688 test_filter_destroy();
690 /* fix prevent: Resource Leak */
691 SAFE_FREE(folder_id);
696 int test_album_list(void)
698 content_debug("\n============Album Test============\n\n");
700 int ret = MEDIA_CONTENT_ERROR_NONE;
705 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
707 ret = media_filter_create(&filter);
708 if (ret != MEDIA_CONTENT_ERROR_NONE) {
709 content_error("Fail to create filter");
712 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
713 if (ret != MEDIA_CONTENT_ERROR_NONE) {
714 media_filter_destroy(filter);
715 content_error("Fail to set condition");
718 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
719 if (ret != MEDIA_CONTENT_ERROR_NONE) {
720 media_filter_destroy(filter);
721 content_error("Fail to set order");
725 ret = media_album_get_album_count_from_db(filter, &album_count);
726 if (ret != MEDIA_CONTENT_ERROR_NONE) {
727 media_filter_destroy(filter);
730 content_debug("album_count [%d]", album_count);
733 ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
734 if (ret != MEDIA_CONTENT_ERROR_NONE)
735 content_error("error media_album_foreach_album_from_db : [%d]", ret);
737 ret = media_filter_destroy(filter);
738 if (ret != MEDIA_CONTENT_ERROR_NONE)
739 content_error("error media_filter_destroy : [%d]", ret);
744 int test_group_operation(void)
746 content_debug("\n============Group Test============\n\n");
748 int ret = MEDIA_CONTENT_ERROR_NONE;
752 ret = test_filter_create();
753 if (ret != MEDIA_CONTENT_ERROR_NONE) {
754 content_error("[error(0x%08x)", ret);
758 for (idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) {
759 ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
760 if (ret != MEDIA_CONTENT_ERROR_NONE) {
761 test_filter_destroy();
762 content_error("media_group_get_group_count_from_db fail. ret=[%d] idx=[%d]", ret, idx);
765 content_debug("[%2d]group_count [%d]", idx, group_count);
768 ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
769 if (ret != MEDIA_CONTENT_ERROR_NONE)
770 content_error("media_group_foreach_group_from_db failed: %d", ret);
772 ret = test_filter_destroy();
777 int test_update_operation()
779 int ret = MEDIA_CONTENT_ERROR_NONE;
781 media_info_h media_handle = NULL;
782 GList *all_item_list = NULL;
784 /* Get all item list */
785 ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
786 if (ret != MEDIA_CONTENT_ERROR_NONE) {
787 content_error("media_info_foreach_media_from_db failed: %d", ret);
790 content_debug("media_info_foreach_media_from_db success");
792 for (i = 0; i < g_list_length(all_item_list); i++) {
793 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
794 get_media_meta(media_handle);
798 return MEDIA_CONTENT_ERROR_NONE;
801 int test_insert(void)
803 int ret = MEDIA_CONTENT_ERROR_NONE;
804 const char *path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
806 const char *path = tzplatform_mkpath(TZ_USER_DOCUMENTS, "other.txt"));
809 media_info_h media_item = NULL;
810 content_debug("\n============DB Insert Test============\n\n");
812 ret = media_info_insert_to_db(path, &media_item);
814 if ((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) {
815 content_debug("Insertion is success");
817 content_error("Insertion is failed");
818 ret = media_info_destroy(media_item);
822 char *media_id = NULL;
824 ret = media_info_get_media_id(media_item, &media_id);
825 if (ret != MEDIA_CONTENT_ERROR_NONE)
826 content_error("media_info_get_media_id failed: %d", ret);
828 content_debug("Media ID: %s", media_id);
832 ret = media_info_destroy(media_item);
833 if (ret != MEDIA_CONTENT_ERROR_NONE)
834 content_error("media_info_destroy failed: %d", ret);
841 int ret = MEDIA_CONTENT_ERROR_NONE;
842 const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
843 const char *dst_path = tzplatform_mkpath(TZ_USER_IMAGES, "XX/Default1.jpg");
844 media_info_h move_media = NULL;
846 ret = media_info_get_media_from_db(move_media_id, &move_media);
847 if (ret == MEDIA_CONTENT_ERROR_NONE)
848 content_debug("media_info_get_media_from_db success");
850 content_error("media_info_get_media_from_db failed: %d", ret);
852 content_debug("\n============DB Move Test============\n\n");
855 ret = media_info_move_to_db(move_media, dst_path);
857 if (ret == MEDIA_CONTENT_ERROR_NONE)
858 content_debug("Move is success");
860 content_error("Move is failed");
862 ret = media_info_destroy(move_media);
864 content_debug("There is no item : %s", move_media_id);
870 int test_create_thumbnail(const char *path)
872 int ret = MEDIA_CONTENT_ERROR_NONE;
874 char *thumb_path = NULL;
876 ret = media_info_insert_to_db(path, &media);
877 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_info_insert_to_db failed [%d]", ret);
879 ret = media_info_generate_thumbnail(media);
880 if (ret != MEDIA_CONTENT_ERROR_NONE) {
881 content_error("media_info_generate_thumbnail failed [%d]", ret);
885 ret = media_info_get_thumbnail_path(media, &thumb_path);
886 if (ret != MEDIA_CONTENT_ERROR_NONE) {
887 content_error("media_info_get_thumbnail_path failed [%d]", ret);
891 content_debug("Thumbnail Path [%s]", thumb_path);
896 media_info_destroy(media);
900 int test_ebook_text_finder(const char *keyword)
902 int ret = MEDIA_CONTENT_ERROR_NONE;
903 char **book_path_list = NULL;
904 unsigned int book_path_len = 0;
906 media_info_h media = NULL;
907 book_meta_h book = NULL;
908 char *s_value = NULL;
909 long long ms_time = 0;
910 struct timeval start_time;
911 struct timeval end_time;
913 gettimeofday(&start_time, NULL);
915 ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
916 if (ret == MEDIA_CONTENT_ERROR_NONE)
917 content_debug("book_meta_get_path_with_keyword is success");
919 content_error("book_meta_get_path_with_keyword is failed");
921 gettimeofday(&end_time, NULL);
923 for (i = 0; i < book_path_len; i++) {
924 ret = media_info_get_media_from_db_by_path(book_path_list[i], &media);
925 if (ret != MEDIA_CONTENT_ERROR_NONE)
928 content_debug("===============================");
929 content_debug("[%d] %s", i, book_path_list[i]);
930 content_debug("===============================");
931 media_info_get_title(media, &s_value);
932 content_debug("Title : %s", s_value);
936 ret = media_info_get_book(media, &book);
937 if (ret != MEDIA_CONTENT_ERROR_NONE) {
938 media_info_destroy(media);
942 ret = book_meta_get_author(book, &s_value);
943 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
944 content_debug("Author : %s", s_value);
949 ret = book_meta_get_date(book, &s_value);
950 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
951 content_debug("Date : %s", s_value);
956 content_debug("===============================");
957 ret = book_meta_destroy(book);
958 if (ret != MEDIA_CONTENT_ERROR_NONE)
959 content_error("book_meta_destroy failed");
961 ret = media_info_destroy(media);
962 if (ret != MEDIA_CONTENT_ERROR_NONE)
963 content_error("media_info_destroy failed");
965 g_free(book_path_list[i]);
968 ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
969 content_debug("Search Time [%lld]", ms_time);
971 g_free(book_path_list);
975 int test_disconnect_database(void)
977 int ret = MEDIA_CONTENT_ERROR_NONE;
978 content_debug("\n============DB Disconnection Test============\n\n");
980 ret = media_content_disconnect();
982 if (ret == MEDIA_CONTENT_ERROR_NONE)
983 content_debug("disconnection is success");
985 content_error("disconnection is failed");
990 static int g_total_photo_size = 0;
991 static int g_total_video_size = 0;
992 static int g_total_mp3_size = 0;
993 static int g_total_voice_memo_size = 0;
995 bool dft_cb(media_info_h media, void *user_data)
997 unsigned long long file_size = 0;
998 media_content_type_e media_type = -1;
999 char *mime_type = NULL;
1000 int ret = MEDIA_CONTENT_ERROR_NONE;
1005 ret = media_info_get_media_type(media, &media_type);
1006 if (ret != MEDIA_CONTENT_ERROR_NONE)
1007 content_error("media_info_get_media_type failed: %d", ret);
1008 ret = media_info_get_size(media, &file_size);
1009 if (ret != MEDIA_CONTENT_ERROR_NONE)
1010 content_error("media_info_get_size failed: %d", ret);
1011 ret = media_info_get_mime_type(media, &mime_type);
1012 if (ret != MEDIA_CONTENT_ERROR_NONE)
1013 content_error("media_info_get_mime_type failed: %d", ret);
1015 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
1016 g_total_photo_size += file_size;
1017 else if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
1018 g_total_video_size += file_size;
1019 else if (media_type == MEDIA_CONTENT_TYPE_SOUND)
1020 g_total_voice_memo_size += file_size;
1021 else if (media_type == MEDIA_CONTENT_TYPE_MUSIC) {
1022 if ((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
1023 g_total_mp3_size += file_size;
1025 g_total_voice_memo_size += file_size;
1027 content_debug("invalid media_type");
1029 SAFE_FREE(mime_type);
1037 int ret = MEDIA_CONTENT_ERROR_NONE;
1038 content_debug("\n============DFT_test============\n\n");
1040 filter_h filter = NULL;
1043 /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
1045 ret = media_filter_create(&filter);
1048 content_debug("[Internal Memory]\n");
1049 /*1. Photo ============================================================*/
1050 ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
1053 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1054 content_debug("Photo count = [%d]\n", media_cnt);
1057 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1058 content_debug("Photo size = [%d]\n", g_total_photo_size);
1060 /*2. Video ============================================================*/
1061 ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
1064 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1065 content_debug("Video count = [%d]\n", media_cnt);
1068 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1069 content_debug("Video size = [%d]\n", g_total_video_size);
1071 /*3. MP3 ============================================================*/
1072 ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
1075 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1076 content_debug("MP3 count = [%d]\n", media_cnt);
1079 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1080 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
1082 /*4. Voice Memo ============================================================*/
1083 ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
1085 /*Get Voice Memo Count*/
1086 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1087 content_debug("Voice Memo count = [%d]\n", media_cnt);
1089 /*Get Voice Memo Size*/
1090 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1091 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
1093 g_total_photo_size = 0;
1094 g_total_video_size = 0;
1095 g_total_mp3_size = 0;
1096 g_total_voice_memo_size = 0;
1099 content_debug("\n[External Memory]\n");
1100 /*1. Photo ============================================================*/
1101 ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
1104 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1105 content_debug("Photo count = [%d]\n", media_cnt);
1108 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1109 content_debug("Photo size = [%d]\n", g_total_photo_size);
1111 /*2. Video ============================================================*/
1112 ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
1115 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1116 content_debug("Video count = [%d]\n", media_cnt);
1119 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1120 content_debug("Video size = [%d]\n", g_total_video_size);
1122 /*3. MP3 ============================================================*/
1123 ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
1126 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1127 content_debug("MP3 count = [%d]\n", media_cnt);
1130 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1131 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
1133 /*4. Voice Memo ============================================================*/
1134 ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
1136 /*Get Voice Memo Count*/
1137 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1138 content_debug("Voice Memo count = [%d]\n", media_cnt);
1140 /*Get Voice Memo Size*/
1141 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1142 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
1143 ret = media_filter_destroy(filter);
1148 void insert_batch_cb(media_content_error_e error, void * user_data)
1150 content_debug("media_info_insert_batch_to_db completed!\n");
1153 int test_batch_operations()
1157 char *file_list[10];
1159 for (i = 0; i < 10; i++) {
1160 file_list[i] = g_strdup_printf("%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), i+1);
1161 content_debug("File : %s\n", file_list[i]);
1164 ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL);
1165 if (ret != MEDIA_CONTENT_ERROR_NONE)
1166 content_error("media_info_insert_batch_to_db failed : %d\n", ret);
1168 for (i = 0; i < 10; i++)
1169 g_free(file_list[i]);
1174 void _scan_cb(media_content_error_e err, void *user_data)
1176 content_debug("scan callback is called : %d\n", err);
1177 g_main_loop_quit(g_loop);
1182 int test_scan_file()
1186 const char *file_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
1187 ret = media_content_scan_file(file_path);
1188 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1189 content_error("Fail to media_content_scan_file : %d", ret);
1196 gboolean test_scan_dir_start(gpointer data)
1200 const char *dir_path = tzplatform_getenv(TZ_USER_CONTENT);
1202 ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL);
1204 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1205 content_error("Fail to test_scan_dir_start : %d", ret);
1212 gboolean cancel_scan_dir_start(gpointer data)
1214 int ret = MEDIA_CONTENT_ERROR_NONE;
1216 const char *dir_path = tzplatform_getenv(TZ_USER_IMAGES);
1218 ret = media_content_cancel_scan_folder(dir_path);
1220 if (ret == MEDIA_CONTENT_ERROR_NONE)
1221 content_debug("media_content_cancel_scan_folder is success");
1223 content_error("media_content_cancel_scan_folder is failed");
1228 int test_scan_dir(int cancel)
1230 GSource *source = NULL;
1231 GMainContext *context = NULL;
1233 g_loop = g_main_loop_new(NULL, FALSE);
1234 context = g_main_loop_get_context(g_loop);
1235 source = g_idle_source_new();
1236 g_source_set_callback(source, test_scan_dir_start, NULL, NULL);
1237 g_source_attach(source, context);
1240 GSource *cancel_src = NULL;
1241 cancel_src = g_idle_source_new();
1242 g_source_set_callback(cancel_src, cancel_scan_dir_start, NULL, NULL);
1243 g_source_attach(cancel_src, context);
1246 g_main_loop_run(g_loop);
1247 g_main_loop_unref(g_loop);
1252 void _noti_cb(media_content_error_e error,
1254 media_content_db_update_item_type_e update_item,
1255 media_content_db_update_type_e update_type,
1256 media_content_type_e media_type,
1263 content_debug("noti success! : %d\n", error);
1265 content_debug("error occurred! : %d\n", error);
1267 content_debug("Noti from PID(%d)\n", pid);
1269 if (update_item == MEDIA_ITEM_FILE)
1270 content_debug("Noti item : MEDIA_ITEM_FILE\n");
1271 else if (update_item == MEDIA_ITEM_DIRECTORY)
1272 content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n");
1274 if (update_type == MEDIA_CONTENT_INSERT)
1275 content_debug("Noti type : MEDIA_CONTENT_INSERT\n");
1276 else if (update_type == MEDIA_CONTENT_DELETE)
1277 content_debug("Noti type : MEDIA_CONTENT_DELETE\n");
1278 else if (update_type == MEDIA_CONTENT_UPDATE)
1279 content_debug("Noti type : MEDIA_CONTENT_UPDATE\n");
1281 content_debug("content type : %d\n", media_type);
1284 content_debug("path : %s\n", path);
1286 content_debug("path not\n");
1289 content_debug("uuid : %s\n", uuid);
1291 content_debug("uuid not\n");
1294 content_debug("mime_type : %s\n", mime_type);
1296 content_debug("mime not\n");
1298 if (user_data) content_debug("String : %s\n", (char *)user_data);
1303 void _noti_cb_2(media_content_error_e error,
1305 media_content_db_update_item_type_e update_item,
1306 media_content_db_update_type_e update_type,
1307 media_content_type_e media_type,
1314 content_debug("noti_2 success! : %d\n", error);
1316 content_debug("error occurred! : %d\n", error);
1318 content_debug("Noti_2 from PID(%d)\n", pid);
1320 g_main_loop_quit(g_loop);
1324 static media_content_noti_h noti_h;
1325 static media_content_noti_h noti_h_2;
1327 gboolean _send_noti_operations(gpointer data)
1329 int ret = MEDIA_CONTENT_ERROR_NONE;
1331 /* First of all, noti subscription */
1332 char *user_str = strdup("hi");
1333 media_content_add_db_updated_cb(_noti_cb, (void*)user_str, ¬i_h);
1334 media_content_add_db_updated_cb(_noti_cb_2, (void*)user_str, ¬i_h_2);
1336 /* media_info_insert_to_db */
1337 media_info_h media_item = NULL;
1338 const char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
1340 ret = media_info_insert_to_db(path, &media_item);
1341 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1342 content_error("media_info_insert_to_db failed : %d", ret);
1343 media_info_destroy(media_item);
1347 content_debug("media_info_insert_to_db success");
1349 media_content_remove_db_updated_cb(noti_h);
1351 media_info_destroy(media_item);
1358 int ret = MEDIA_CONTENT_ERROR_NONE;
1359 GSource *source = NULL;
1360 GMainContext *context = NULL;
1362 g_loop = g_main_loop_new(NULL, FALSE);
1363 context = g_main_loop_get_context(g_loop);
1364 source = g_idle_source_new();
1365 g_source_set_callback(source, _send_noti_operations, NULL, NULL);
1366 g_source_attach(source, context);
1368 g_main_loop_run(g_loop);
1369 g_main_loop_unref(g_loop);
1371 test_filter_destroy();
1372 media_content_remove_db_updated_cb(noti_h_2);
1376 #ifdef _USE_TVPD_MODE
1377 filter_h g_tv_filter = NULL;
1379 int test_tv_filter_create(void)
1381 content_debug("\n============Filter Create============\n\n");
1383 int ret = MEDIA_CONTENT_ERROR_NONE;
1385 ret = media_filter_create(&g_tv_filter);
1387 ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
1389 ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
1394 int test_tv_filter_destroy(void)
1396 content_debug("\n============Filter Destroy============\n\n");
1398 int ret = MEDIA_CONTENT_ERROR_NONE;
1400 ret = media_filter_destroy(g_tv_filter);
1405 bool pvr_item_cb(media_pvr_h pvr, void *user_data)
1407 int ret = MEDIA_CONTENT_ERROR_NONE;
1408 char *c_value = NULL;
1410 bool b_value = false;
1411 unsigned long long l_value = 0;
1414 content_debug("NO Item");
1418 ret = media_pvr_get_media_id(pvr, &c_value);
1419 if (ret != MEDIA_CONTENT_ERROR_NONE)
1420 content_error("Fail to media_pvr_get_media_id");
1421 content_debug("media_id [%s]", c_value);
1424 ret = media_pvr_get_channel_name(pvr, &c_value);
1425 if (ret != MEDIA_CONTENT_ERROR_NONE)
1426 content_error("Fail to media_pvr_get_channel_name");
1427 content_debug("channel_name [%s]", c_value);
1430 ret = media_pvr_get_program_title(pvr, &c_value);
1431 if (ret != MEDIA_CONTENT_ERROR_NONE)
1432 content_error("Fail to media_pvr_get_program_title");
1433 content_debug("program_title [%s]", c_value);
1436 ret = media_pvr_get_program_crid(pvr, &c_value);
1437 if (ret != MEDIA_CONTENT_ERROR_NONE)
1438 content_error("Fail to media_pvr_get_program_crid");
1439 content_debug("program_crid [%s]", c_value);
1442 ret = media_pvr_get_guidance(pvr, &c_value);
1443 if (ret != MEDIA_CONTENT_ERROR_NONE)
1444 content_error("Fail to media_pvr_get_guidance");
1445 content_debug("guidance [%s]", c_value);
1448 ret = media_pvr_get_synopsis(pvr, &c_value);
1449 if (ret != MEDIA_CONTENT_ERROR_NONE)
1450 content_error("Fail to media_pvr_get_synopsis");
1451 content_debug("synopsis [%s]", c_value);
1454 ret = media_pvr_get_genre(pvr, &c_value);
1455 if (ret != MEDIA_CONTENT_ERROR_NONE)
1456 content_error("Fail to media_pvr_get_synopsis");
1457 content_debug("genre [%s]", c_value);
1460 ret = media_pvr_get_language(pvr, &c_value);
1461 if (ret != MEDIA_CONTENT_ERROR_NONE)
1462 content_error("Fail to media_pvr_get_language");
1463 content_debug("language [%s]", c_value);
1466 ret = media_pvr_get_path(pvr, &c_value);
1467 if (ret != MEDIA_CONTENT_ERROR_NONE)
1468 content_error("Fail to media_pvr_get_path");
1469 content_debug("path [%s]", c_value);
1472 ret = media_pvr_get_storage_id(pvr, &c_value);
1473 if (ret != MEDIA_CONTENT_ERROR_NONE)
1474 content_error("Fail to media_pvr_get_storage_id");
1475 content_debug("storage_id [%s]", c_value);
1478 ret = media_pvr_get_size(pvr, &l_value);
1479 if (ret != MEDIA_CONTENT_ERROR_NONE)
1480 content_error("Fail to media_pvr_get_size");
1481 content_debug("size [%lld]", l_value);
1483 ret = media_pvr_get_timezone(pvr, &i_value);
1484 if (ret != MEDIA_CONTENT_ERROR_NONE)
1485 content_error("Fail to media_pvr_get_timezone");
1486 content_debug("timezone [%d]", i_value);
1488 ret = media_pvr_get_ptc(pvr, &i_value);
1489 if (ret != MEDIA_CONTENT_ERROR_NONE)
1490 content_error("Fail to media_pvr_get_ptc");
1491 content_debug("ptc [%d]", i_value);
1493 ret = media_pvr_get_major(pvr, &i_value);
1494 if (ret != MEDIA_CONTENT_ERROR_NONE)
1495 content_error("Fail to media_pvr_get_major");
1496 content_debug("[%d]", i_value);
1498 ret = media_pvr_get_minor(pvr, &i_value);
1499 if (ret != MEDIA_CONTENT_ERROR_NONE)
1500 content_error("Fail to media_pvr_get_minor");
1501 content_debug("minor [%d]", i_value);
1503 ret = media_pvr_get_channel_type(pvr, &i_value);
1504 if (ret != MEDIA_CONTENT_ERROR_NONE)
1505 content_error("Fail to media_pvr_get_channel_type");
1506 content_debug("channel_type [%d]", i_value);
1508 ret = media_pvr_get_program_num(pvr, &i_value);
1509 if (ret != MEDIA_CONTENT_ERROR_NONE)
1510 content_error("Fail to media_pvr_get_program_num");
1511 content_debug("program_num [%d]", i_value);
1513 unsigned int ui_value = 0;
1514 ret = media_pvr_get_service_profile(pvr, &ui_value);
1515 if (ret != MEDIA_CONTENT_ERROR_NONE)
1516 content_error("Fail to media_pvr_get_service_profile");
1517 content_debug("service_profile [%u]", ui_value);
1519 ret = media_pvr_get_duration(pvr, &i_value);
1520 if (ret != MEDIA_CONTENT_ERROR_NONE)
1521 content_error("Fail to media_pvr_get_duration");
1522 content_debug("duration [%d]", i_value);
1524 ret = media_pvr_get_embargo_time(pvr, &i_value);
1525 if (ret != MEDIA_CONTENT_ERROR_NONE)
1526 content_error("Fail to media_pvr_get_embargo_time");
1527 content_debug("embargo_time [%d]", i_value);
1529 ret = media_pvr_get_expiry_time(pvr, &i_value);
1530 if (ret != MEDIA_CONTENT_ERROR_NONE)
1531 content_error("Fail to media_pvr_get_expiry_time");
1532 content_debug("expiry_time [%d]", i_value);
1534 ret = media_pvr_get_parental_rating(pvr, &i_value);
1535 if (ret != MEDIA_CONTENT_ERROR_NONE)
1536 content_error("Fail to media_pvr_get_parental_rating");
1537 content_debug("parental_rating [%d]", i_value);
1539 ret = media_pvr_get_start_time(pvr, &i_value);
1540 if (ret != MEDIA_CONTENT_ERROR_NONE)
1541 content_error("Fail to media_pvr_get_start_time");
1542 content_debug("start_time [%d]", i_value);
1544 ret = media_pvr_get_program_start_time(pvr, &i_value);
1545 if (ret != MEDIA_CONTENT_ERROR_NONE)
1546 content_error("Fail to media_pvr_get_program_start_time");
1547 content_debug("program_start_time [%d]", i_value);
1549 ret = media_pvr_get_program_end_time(pvr, &i_value);
1550 if (ret != MEDIA_CONTENT_ERROR_NONE)
1551 content_error("Fail to media_pvr_get_program_end_time");
1552 content_debug("program_end_time [%d]", i_value);
1554 ret = media_pvr_get_program_date(pvr, &i_value);
1555 if (ret != MEDIA_CONTENT_ERROR_NONE)
1556 content_error("Fail to media_pvr_get_program_date");
1557 content_debug("program_date [%d]", i_value);
1559 ret = media_pvr_get_timer_record(pvr, &b_value);
1560 if (ret != MEDIA_CONTENT_ERROR_NONE)
1561 content_error("Fail to media_pvr_get_timer_record");
1562 content_debug("timer_record [%d]", b_value);
1564 ret = media_pvr_get_series_record(pvr, &b_value);
1565 if (ret != MEDIA_CONTENT_ERROR_NONE)
1566 content_error("Fail to media_pvr_get_series_record");
1567 content_debug("series_record [%d]", b_value);
1569 ret = media_pvr_get_hd(pvr, &i_value);
1570 if (ret != MEDIA_CONTENT_ERROR_NONE)
1571 content_error("Fail to media_pvr_get_hd");
1572 content_debug("hd [%d]", i_value);
1574 ret = media_pvr_get_subtitle(pvr, &b_value);
1575 if (ret != MEDIA_CONTENT_ERROR_NONE)
1576 content_error("Fail to media_pvr_get_subtitle");
1577 content_debug("subtitle [%d]", b_value);
1579 ret = media_pvr_get_ttx(pvr, &b_value);
1580 if (ret != MEDIA_CONTENT_ERROR_NONE)
1581 content_error("Fail to media_pvr_get_ttx");
1582 content_debug("ttx [%d]", b_value);
1584 ret = media_pvr_get_ad(pvr, &b_value);
1585 if (ret != MEDIA_CONTENT_ERROR_NONE)
1586 content_error("Fail to media_pvr_get_ad");
1587 content_debug("ad [%d]", b_value);
1589 ret = media_pvr_get_hard_of_hearing_radio(pvr, &b_value);
1590 if (ret != MEDIA_CONTENT_ERROR_NONE)
1591 content_error("Fail to media_pvr_get_hard_of_hearing_radio");
1592 content_debug("hard_of_hearing_radio [%d]", b_value);
1594 ret = media_pvr_get_data_service(pvr, &b_value);
1595 if (ret != MEDIA_CONTENT_ERROR_NONE)
1596 content_error("Fail to media_pvr_get_data_service");
1597 content_debug("data_service [%d]", b_value);
1599 ret = media_pvr_get_content_lock(pvr, &b_value);
1600 if (ret != MEDIA_CONTENT_ERROR_NONE)
1601 content_error("Fail to media_pvr_get_content_lock");
1602 content_debug("content_lock [%d]", b_value);
1604 ret = media_pvr_get_content_watch(pvr, &b_value);
1605 if (ret != MEDIA_CONTENT_ERROR_NONE)
1606 content_error("Fail to media_pvr_get_content_watch");
1607 content_debug("content_watch [%d]", b_value);
1609 ret = media_pvr_get_has_audio_only(pvr, &b_value);
1610 if (ret != MEDIA_CONTENT_ERROR_NONE)
1611 content_error("Fail to media_pvr_get_has_audio_only");
1612 content_debug("has_audio_only [%d]", b_value);
1614 ret = media_pvr_get_is_local_record(pvr, &b_value);
1615 if (ret != MEDIA_CONTENT_ERROR_NONE)
1616 content_error("Fail to media_pvr_get_is_local_record");
1617 content_debug("is_local_record [%d]", b_value);
1619 ret = media_pvr_get_resolution(pvr, (media_pvr_resolution_e*)&i_value);
1620 if (ret != MEDIA_CONTENT_ERROR_NONE)
1621 content_error("Fail to media_pvr_get_resolution");
1622 content_debug("resolution [%d]", i_value);
1624 ret = media_pvr_get_aspectratio(pvr, (media_pvr_aspectratio_e*)&i_value);
1625 if (ret != MEDIA_CONTENT_ERROR_NONE)
1626 content_error("Fail to media_pvr_get_aspectratio");
1627 content_debug("aspectratio [%d]", i_value);
1634 int ret = MEDIA_CONTENT_ERROR_NONE;
1636 content_debug("\n============PVR Test============\n\n");
1638 test_tv_filter_create();
1640 ret = media_pvr_foreach_media_from_db(g_tv_filter, pvr_item_cb, NULL);
1641 if (ret != MEDIA_CONTENT_ERROR_NONE)
1642 content_error("media_pvr_foreach_media_from_db is failed");
1644 test_tv_filter_destroy();
1649 int test_pvr_update_db(void)
1651 int ret = MEDIA_CONTENT_ERROR_NONE;
1652 media_pvr_h pvr = NULL;
1654 ret = media_pvr_get_pvr_from_db("ff9b5a9a-a7b4-47f4-8255-84e007e25f13", &pvr);
1655 if (ret != MEDIA_CONTENT_ERROR_NONE)
1656 content_error("media_pvr_get_pvr_from_db failed: %d", ret);
1658 ret = media_pvr_set_content_lock(pvr, TRUE);
1659 if (ret != MEDIA_CONTENT_ERROR_NONE)
1660 content_error("Fail to media_pvr_set_content_lock");
1662 ret = media_pvr_set_content_watch(pvr, TRUE);
1663 if (ret != MEDIA_CONTENT_ERROR_NONE)
1664 content_error("Fail to media_pvr_set_content_watch");
1666 ret = media_pvr_set_program_title(pvr, "TEST TITLE");
1667 if (ret != MEDIA_CONTENT_ERROR_NONE)
1668 content_error("Fail to media_pvr_set_program_title");
1670 ret = media_pvr_update_to_db(pvr);
1671 if (ret != MEDIA_CONTENT_ERROR_NONE)
1672 content_error("Fail to media_pvr_update_to_db");
1675 media_pvr_destroy(pvr);
1681 int main(int argc, char *argv[])
1683 int ret = MEDIA_CONTENT_ERROR_NONE;
1685 content_debug("--- content manager test start ---\n\n");
1687 ret = test_connect_database();
1688 if (ret != MEDIA_CONTENT_ERROR_NONE)
1689 return MEDIA_CONTENT_ERROR_NONE;
1690 #ifdef _USE_TVPD_MODE
1693 test_pvr_update_db();
1700 ret = test_ebook_text_finder(argv[1]);
1701 if (ret != MEDIA_CONTENT_ERROR_NONE)
1706 if (ret != MEDIA_CONTENT_ERROR_NONE)
1709 ret = test_gallery_scenario();
1710 if (ret != MEDIA_CONTENT_ERROR_NONE)
1713 ret = test_get_all_music_files();
1714 if (ret != MEDIA_CONTENT_ERROR_NONE)
1717 ret = test_media_info_operation();
1718 if (ret != MEDIA_CONTENT_ERROR_NONE)
1721 ret = test_folder_operation();
1722 if (ret != MEDIA_CONTENT_ERROR_NONE)
1725 ret = test_album_list();
1726 if (ret != MEDIA_CONTENT_ERROR_NONE)
1729 ret = test_group_operation();
1730 if (ret != MEDIA_CONTENT_ERROR_NONE)
1733 ret = test_update_operation();
1734 if (ret != MEDIA_CONTENT_ERROR_NONE)
1737 ret = test_insert();
1738 if (ret != MEDIA_CONTENT_ERROR_NONE)
1742 if (ret != MEDIA_CONTENT_ERROR_NONE)
1746 ret = test_create_thumbnail(argv[1]);
1747 if (ret != MEDIA_CONTENT_ERROR_NONE)
1752 if (ret != MEDIA_CONTENT_ERROR_NONE)
1755 ret = test_batch_operations();
1756 if (ret != MEDIA_CONTENT_ERROR_NONE)
1757 return MEDIA_CONTENT_ERROR_NONE;
1759 ret = test_scan_file();
1760 if (ret != MEDIA_CONTENT_ERROR_NONE)
1761 return MEDIA_CONTENT_ERROR_NONE;
1763 ret = test_scan_dir(true);
1764 if (ret != MEDIA_CONTENT_ERROR_NONE)
1765 return MEDIA_CONTENT_ERROR_NONE;
1768 if (ret != MEDIA_CONTENT_ERROR_NONE)
1769 return MEDIA_CONTENT_ERROR_NONE;
1772 ret = test_disconnect_database();
1773 if (ret != MEDIA_CONTENT_ERROR_NONE)
1776 content_debug("--- content manager test end ---\n");