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"
36 static void get_audio_meta(media_info_h media)
38 audio_meta_h audio = NULL;
41 content_debug("=== audio meta ===");
42 if (media_info_get_audio(media, &audio) != MEDIA_CONTENT_ERROR_NONE)
45 if (audio_meta_get_media_id(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
46 content_debug("audio_id : [%s]", c_value);
50 if (audio_meta_get_album(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
51 content_debug("album : [%s]", c_value);
55 if (audio_meta_get_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
56 content_debug("artist : [%s]", c_value);
60 if (audio_meta_get_album_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
61 content_debug("album artist : [%s]", c_value);
65 if (audio_meta_get_genre(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
66 content_debug("genre : [%s]", c_value);
70 if (audio_meta_get_year(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
71 content_debug("year : [%s]", c_value);
75 if (audio_meta_get_track_num(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
76 content_debug("track number : [%s]", c_value);
80 audio_meta_destroy(audio);
83 static void get_image_meta(media_info_h media)
85 image_meta_h image = NULL;
88 media_content_orientation_e orientation;
90 content_debug("=== image meta ===");
91 if (media_info_get_image(media, &image) != MEDIA_CONTENT_ERROR_NONE)
94 if (image_meta_get_width(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
95 content_debug("width : [%d]", i_value);
97 if (image_meta_get_height(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
98 content_debug("height : [%d]", i_value);
100 if (image_meta_get_orientation(image, &orientation) == MEDIA_CONTENT_ERROR_NONE)
101 content_debug("orientation : [%d]", orientation);
103 if (image_meta_get_date_taken(image, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
104 content_debug("datetaken : [%s]", c_value);
108 image_meta_destroy(image);
111 static void get_book_meta(media_info_h media)
113 book_meta_h book = NULL;
114 char *c_value = NULL;
116 content_debug("=== book meta ===");
117 if (media_info_get_book(media, &book) != MEDIA_CONTENT_ERROR_NONE)
120 if (book_meta_get_media_id(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
121 content_debug("media_id : [%s]", c_value);
125 if (book_meta_get_author(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
126 content_debug("author : [%s]", c_value);
130 if (book_meta_get_subject(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
131 content_debug("subject : [%s]", c_value);
135 book_meta_destroy(book);
138 static void get_album_meta(media_album_h album)
140 char *c_value = NULL;
143 content_debug("=== album meta ===");
144 if (media_album_get_album_id(album, &i_value) == MEDIA_CONTENT_ERROR_NONE)
145 content_debug("album id : [%d]", i_value);
147 if (media_album_get_name(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
148 content_debug("album name : [%s]", c_value);
152 if (media_album_get_artist(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
153 content_debug("album artist : [%s]", c_value);
158 static void get_folder_meta(media_folder_h folder, char **folder_id)
160 char *c_value = NULL;
162 content_debug("=== folder meta ===");
163 if (media_folder_get_folder_id(folder, &c_value) != MEDIA_CONTENT_ERROR_NONE) {
164 content_debug("folder_id : %s", c_value);
165 *folder_id = c_value;
168 if (media_folder_get_path(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
169 content_debug("folder_path : %s", c_value);
173 if (media_folder_get_name(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
174 content_debug("folder_name : %s", c_value);
179 static void get_media_meta(media_info_h media)
181 char *c_value = NULL;
183 unsigned long long size = 0;
184 media_content_type_e media_type = 0;
185 #ifdef _USE_TVPD_MODE
189 content_debug("=== media meta ===");
190 if (media_info_get_media_type(media, &media_type) == MEDIA_CONTENT_ERROR_NONE)
191 content_debug("media_type : [%d]", media_type);
193 if (media_info_get_media_id(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
194 content_debug("media_id : [%s]", c_value);
198 if (media_info_get_file_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
199 content_debug("file_path : [%s]", c_value);
203 if (media_info_get_display_name(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
204 content_debug("display_name : [%s]", c_value);
208 if (media_info_get_mime_type(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
209 content_debug("mime_type : [%s]", c_value);
213 if (media_info_get_thumbnail_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
214 content_debug("thumbnail_path : [%s]", c_value);
218 if (media_info_get_size(media, &size) == MEDIA_CONTENT_ERROR_NONE)
219 content_debug("size : [%lld]", size);
221 if (media_info_get_added_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
222 content_debug("added_time : [%ld]", t_value);
224 if (media_info_get_modified_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
225 content_debug("modified_time : [%ld]", t_value);
227 #ifdef _USE_TVPD_MODE
228 if (media_info_get_stitched_state(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
229 content_debug("360 stitched : [%d]", i_value);
232 if (media_type == MEDIA_CONTENT_TYPE_MUSIC)
233 get_audio_meta(media);
235 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
236 get_image_meta(media);
238 if (media_type == MEDIA_CONTENT_TYPE_BOOK)
239 get_book_meta(media);
241 if (media_type == MEDIA_CONTENT_TYPE_OTHERS)
242 content_debug("Other type");
245 bool media_item_cb(media_info_h media, void *user_data)
248 content_debug("NO Item");
252 get_media_meta(media);
257 bool gallery_folder_list_cb(media_folder_h folder, void *user_data)
259 media_folder_h new_folder = NULL;
260 media_folder_clone(&new_folder, folder);
262 GList **list = (GList**)user_data;
263 *list = g_list_append(*list, new_folder);
268 bool gallery_media_item_cb(media_info_h media, void *user_data)
270 media_info_h new_media = NULL;
271 int ret = MEDIA_CONTENT_ERROR_NONE;
273 ret = media_info_clone(&new_media, media);
275 if (ret != MEDIA_CONTENT_ERROR_NONE) {
276 GList **list = (GList**)user_data;
277 *list = g_list_append(*list, new_media);
283 bool folder_list_cb(media_folder_h folder, void *user_data)
286 char *folder_id = NULL;
287 media_folder_h *_folder = (media_folder_h*)user_data;
289 content_debug("===========================");
290 if (folder != NULL) {
292 media_folder_clone(_folder, folder);
294 get_folder_meta(folder, &folder_id);
296 if (media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) {
297 SAFE_FREE(folder_id);
298 content_error("[ERROR] media_folder_get_media_count_from_db is failed");
302 if (media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) {
303 SAFE_FREE(folder_id);
304 content_error("[ERROR] media_folder_foreach_media_from_db is failed");
308 SAFE_FREE(folder_id);
316 bool album_list_cb(media_album_h album, void *user_data)
320 int ret = MEDIA_CONTENT_ERROR_NONE;
323 get_album_meta(album);
324 media_album_get_album_id(album, &album_id);
326 ret = media_album_get_media_count_from_db(album_id, NULL, &media_count);
327 if (ret != MEDIA_CONTENT_ERROR_NONE)
328 content_error("error media_album_get_media_count_from_db : [%d]", ret);
330 content_debug("media_count : [%d]", media_count);
332 ret = media_album_foreach_media_from_db(album_id, NULL, media_item_cb, NULL);
333 if (ret != MEDIA_CONTENT_ERROR_NONE) {
334 content_error("error media_album_foreach_media_from_db : [%d]", ret);
339 content_error("album item not Found!!");
345 bool group_list_cb(const char *group_name, void *user_data)
348 int *idx = user_data;
350 content_debug("group item : [%s] [%d]", group_name, *idx);
352 if (media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
355 content_debug("media_count : [%d]", media_count);
357 if (media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
363 int test_filter_create(void)
365 content_debug("\n============Filter Create============\n\n");
367 int ret = MEDIA_CONTENT_ERROR_NONE;
369 /* Filter for media */
370 const char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
372 ret = media_filter_create(&g_filter);
374 /* Set condition and collate
375 * Condition string : You can make where statement of sql.
376 * Colation : You can use collation when comparing.
377 * Ex) In case of FILE_NAME='Samsung' as condition string,
378 * if you want to compare with NOCASE collation,
379 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
380 * if you want to compare in case-sensitive,
381 * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
383 ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
388 int test_filter_destroy(void)
390 content_debug("\n============Filter Create============\n\n");
392 int ret = MEDIA_CONTENT_ERROR_NONE;
394 ret = media_filter_destroy(g_filter);
399 int test_connect_database(void)
401 int ret = MEDIA_CONTENT_ERROR_NONE;
403 content_debug("\n============DB Connection Test============\n\n");
405 ret = media_content_connect();
407 if (ret == MEDIA_CONTENT_ERROR_NONE)
408 content_debug("connection is success\n\n");
410 content_error("connection is failed\n\n");
415 int test_gallery_scenario(void)
417 int ret = MEDIA_CONTENT_ERROR_NONE;
419 filter_h filter = NULL;
422 GList *folder_list = NULL;
423 media_folder_h folder_handle = NULL;
425 /* First, Get folder list */
426 ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
427 if (ret != MEDIA_CONTENT_ERROR_NONE) {
428 content_error("media_folder_foreach_folder_from_db failed: %d", ret);
431 content_debug("media_folder_foreach_folder_from_db success!!");
432 char *folder_id = NULL;
434 for (i = 0; i < g_list_length(folder_list); i++) {
435 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
437 get_folder_meta(folder_handle, &folder_id);
439 ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
440 SAFE_FREE(folder_id);
441 if (ret != MEDIA_CONTENT_ERROR_NONE) {
442 content_error("media_folder_get_media_count_from_db failed: %d", ret);
445 content_debug("media count [%d] : %d", i, count);
450 /* To check performance */
451 struct timeval start, end;
452 gettimeofday(&start, NULL);
454 /* Second, Get all item list */
455 media_info_h media_handle = NULL;
456 GList *all_item_list = NULL;
458 media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
459 media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
460 ret = media_filter_create(&filter);
461 if (ret != MEDIA_CONTENT_ERROR_NONE) {
462 content_error("Fail to create filter");
465 ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
466 if (ret != MEDIA_CONTENT_ERROR_NONE) {
467 media_filter_destroy(filter);
468 content_error("Fail to set condition");
471 ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
472 if (ret != MEDIA_CONTENT_ERROR_NONE) {
473 media_filter_destroy(filter);
474 content_error("Fail to set order");
478 ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
479 if (ret != MEDIA_CONTENT_ERROR_NONE) {
480 content_error("media_info_foreach_media_from_db failed: %d", ret);
481 media_filter_destroy(filter);
484 content_debug("media_info_foreach_media_from_db success");
486 for (i = 0; i < g_list_length(all_item_list); i++) {
487 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
488 get_media_meta(media_handle);
492 media_filter_destroy(filter);
495 /* To check performance */
496 gettimeofday(&end, NULL);
497 long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
498 content_debug("Time : %ld\n", time);
500 /* Third, Get item list of a folder */
501 GList *item_list = NULL;
503 for (i = 0; i < g_list_length(folder_list); i++) {
505 char *folder_id = NULL;
506 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
508 get_folder_meta(folder_handle, &folder_id);
510 ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
511 SAFE_FREE(folder_id);
513 if (ret != MEDIA_CONTENT_ERROR_NONE) {
514 content_error("media_folder_foreach_media_from_db failed: %d", ret);
517 content_error("media_folder_foreach_media_from_db success!");
519 for (j = 0; j < g_list_length(item_list); j++) {
520 media_handle = (media_info_h)g_list_nth_data(item_list, j);
521 get_media_meta(media_handle);
526 /* Remove folder list */
528 for (i = 0; i < g_list_length(folder_list); i++) {
529 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
530 media_folder_destroy(folder_handle);
533 g_list_free(folder_list);
536 /* Remove all items list */
538 for (i = 0; i < g_list_length(all_item_list); i++) {
539 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
540 ret = media_info_destroy(media_handle);
541 if (ret != MEDIA_CONTENT_ERROR_NONE)
542 content_error("media_info_destroy failed: %d", ret);
545 g_list_free(all_item_list);
548 /* Remove items list */
550 for (i = 0; i < g_list_length(item_list); i++) {
551 media_handle = (media_info_h)g_list_nth_data(item_list, i);
552 ret = media_info_destroy(media_handle);
553 if (ret != MEDIA_CONTENT_ERROR_NONE)
554 content_error("media_info_destroy failed: %d", ret);
557 g_list_free(item_list);
560 return MEDIA_CONTENT_ERROR_NONE;
563 /*Get All Music file. sort by Title and not case sensitive*/
564 int test_get_all_music_files(void)
566 int ret = MEDIA_CONTENT_ERROR_NONE;
571 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
573 ret = media_filter_create(&filter);
574 if (ret != MEDIA_CONTENT_ERROR_NONE) {
575 content_error("Fail to create filter");
578 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED);
579 if (ret != MEDIA_CONTENT_ERROR_NONE) {
580 media_filter_destroy(filter);
581 content_error("Fail to set condition");
584 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED);
585 if (ret != MEDIA_CONTENT_ERROR_NONE) {
586 media_filter_destroy(filter);
587 content_error("Fail to set order");
592 ret = media_info_get_media_count_from_db(filter, &media_count);
593 if (ret != MEDIA_CONTENT_ERROR_NONE) {
594 media_filter_destroy(filter);
595 content_error("Fail to get media count");
599 content_debug("media_count : [%d]", media_count);
601 ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
602 if (ret != MEDIA_CONTENT_ERROR_NONE) {
603 media_filter_destroy(filter);
604 content_error("Fail to get media");
608 ret = media_filter_destroy(filter);
613 int test_media_info_operation(void)
615 int ret = MEDIA_CONTENT_ERROR_NONE;
618 content_debug("\n============Media info Test============\n\n");
620 test_filter_create();
622 ret = media_info_get_media_count_from_db(g_filter, &media_count);
623 if (ret != MEDIA_CONTENT_ERROR_NONE)
624 content_error("media_info_get_media_count_from_db failed: %d", ret);
626 content_debug("media_count : [%d]", media_count);
628 ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
629 if (ret == MEDIA_CONTENT_ERROR_NONE)
630 content_debug("media_info_foreach_media_from_db is success");
632 content_error("media_info_foreach_media_from_db is failed");
634 test_filter_destroy();
639 int test_folder_operation(void)
641 int ret = MEDIA_CONTENT_ERROR_NONE;
642 filter_h filter = NULL;
643 media_folder_h folder = NULL;
644 char *folder_id = NULL;
647 content_debug("\n============Folder Test============\n\n");
649 test_filter_create();
651 ret = media_filter_create(&filter);
652 if (ret != MEDIA_CONTENT_ERROR_NONE) {
653 content_error("[ERROR] media_folder_filter_create is failed");
657 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*/
658 media_filter_set_offset(filter, 0, 5);
659 media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
661 ret = media_folder_get_folder_count_from_db(filter, &count);
662 content_debug("Folder count : [%d]", count);
664 ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
666 filter_h m_filter = NULL;
668 ret = media_filter_create(&m_filter);
669 if (ret != MEDIA_CONTENT_ERROR_NONE) {
670 test_filter_destroy();
671 media_filter_destroy(filter);
672 content_error("[ERROR] media_info_filter_create is failed");
676 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*/
677 media_filter_set_offset(m_filter, 0, 5);
678 media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
680 ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
681 if (ret != MEDIA_CONTENT_ERROR_NONE)
682 content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret);
684 media_filter_destroy(filter);
685 media_filter_destroy(m_filter);
687 test_filter_destroy();
689 /* fix prevent: Resource Leak */
690 SAFE_FREE(folder_id);
695 int test_album_list(void)
697 content_debug("\n============Album Test============\n\n");
699 int ret = MEDIA_CONTENT_ERROR_NONE;
704 const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
706 ret = media_filter_create(&filter);
707 if (ret != MEDIA_CONTENT_ERROR_NONE) {
708 content_error("Fail to create filter");
711 ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
712 if (ret != MEDIA_CONTENT_ERROR_NONE) {
713 media_filter_destroy(filter);
714 content_error("Fail to set condition");
717 ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
718 if (ret != MEDIA_CONTENT_ERROR_NONE) {
719 media_filter_destroy(filter);
720 content_error("Fail to set order");
724 ret = media_album_get_album_count_from_db(filter, &album_count);
725 if (ret != MEDIA_CONTENT_ERROR_NONE) {
726 media_filter_destroy(filter);
729 content_debug("album_count [%d]", album_count);
732 ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
733 if (ret != MEDIA_CONTENT_ERROR_NONE)
734 content_error("error media_album_foreach_album_from_db : [%d]", ret);
736 ret = media_filter_destroy(filter);
737 if (ret != MEDIA_CONTENT_ERROR_NONE)
738 content_error("error media_filter_destroy : [%d]", ret);
743 int test_group_operation(void)
745 content_debug("\n============Group Test============\n\n");
747 int ret = MEDIA_CONTENT_ERROR_NONE;
751 ret = test_filter_create();
752 if (ret != MEDIA_CONTENT_ERROR_NONE) {
753 content_error("[error(0x%08x)", ret);
757 for (idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) {
758 ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
759 if (ret != MEDIA_CONTENT_ERROR_NONE) {
760 test_filter_destroy();
761 content_error("media_group_get_group_count_from_db fail. ret=[%d] idx=[%d]", ret, idx);
764 content_debug("[%2d]group_count [%d]", idx, group_count);
767 ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
768 if (ret != MEDIA_CONTENT_ERROR_NONE)
769 content_error("media_group_foreach_group_from_db failed: %d", ret);
771 ret = test_filter_destroy();
776 int test_update_operation()
778 int ret = MEDIA_CONTENT_ERROR_NONE;
780 media_info_h media_handle = NULL;
781 GList *all_item_list = NULL;
783 /* Get all item list */
784 ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
785 if (ret != MEDIA_CONTENT_ERROR_NONE) {
786 content_error("media_info_foreach_media_from_db failed: %d", ret);
789 content_debug("media_info_foreach_media_from_db success");
791 for (i = 0; i < g_list_length(all_item_list); i++) {
792 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
793 get_media_meta(media_handle);
797 return MEDIA_CONTENT_ERROR_NONE;
800 int test_insert(void)
802 int ret = MEDIA_CONTENT_ERROR_NONE;
803 const char *path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
805 const char *path = tzplatform_mkpath(TZ_USER_DOCUMENTS, "other.txt"));
808 media_info_h media_item = NULL;
809 content_debug("\n============DB Insert Test============\n\n");
811 ret = media_info_insert_to_db(path, &media_item);
813 if ((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) {
814 content_debug("Insertion is success");
816 content_error("Insertion is failed");
817 ret = media_info_destroy(media_item);
821 char *media_id = NULL;
823 ret = media_info_get_media_id(media_item, &media_id);
824 if (ret != MEDIA_CONTENT_ERROR_NONE)
825 content_error("media_info_get_media_id failed: %d", ret);
827 content_debug("Media ID: %s", media_id);
831 ret = media_info_destroy(media_item);
832 if (ret != MEDIA_CONTENT_ERROR_NONE)
833 content_error("media_info_destroy failed: %d", ret);
840 int ret = MEDIA_CONTENT_ERROR_NONE;
841 const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
842 const char *dst_path = tzplatform_mkpath(TZ_USER_IMAGES, "XX/Default1.jpg");
843 media_info_h move_media = NULL;
845 ret = media_info_get_media_from_db(move_media_id, &move_media);
846 if (ret == MEDIA_CONTENT_ERROR_NONE)
847 content_debug("media_info_get_media_from_db success");
849 content_error("media_info_get_media_from_db failed: %d", ret);
851 content_debug("\n============DB Move Test============\n\n");
854 ret = media_info_move_to_db(move_media, dst_path);
856 if (ret == MEDIA_CONTENT_ERROR_NONE)
857 content_debug("Move is success");
859 content_error("Move is failed");
861 ret = media_info_destroy(move_media);
863 content_debug("There is no item : %s", move_media_id);
869 int test_create_thumbnail(const char *path)
871 int ret = MEDIA_CONTENT_ERROR_NONE;
873 char *thumb_path = NULL;
875 ret = media_info_insert_to_db(path, &media);
876 content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_info_insert_to_db failed [%d]", ret);
878 ret = media_info_generate_thumbnail(media);
879 if (ret != MEDIA_CONTENT_ERROR_NONE) {
880 content_error("media_info_generate_thumbnail failed [%d]", ret);
884 ret = media_info_get_thumbnail_path(media, &thumb_path);
885 if (ret != MEDIA_CONTENT_ERROR_NONE) {
886 content_error("media_info_get_thumbnail_path failed [%d]", ret);
890 content_debug("Thumbnail Path [%s]", thumb_path);
895 media_info_destroy(media);
899 int test_ebook_text_finder(const char *keyword)
901 int ret = MEDIA_CONTENT_ERROR_NONE;
902 char **book_path_list = NULL;
903 unsigned int book_path_len = 0;
905 media_info_h media = NULL;
906 book_meta_h book = NULL;
907 char *s_value = NULL;
908 long long ms_time = 0;
909 struct timeval start_time;
910 struct timeval end_time;
912 gettimeofday(&start_time, NULL);
914 ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
915 if (ret == MEDIA_CONTENT_ERROR_NONE)
916 content_debug("book_meta_get_path_with_keyword is success");
918 content_error("book_meta_get_path_with_keyword is failed");
920 gettimeofday(&end_time, NULL);
922 for (i = 0; i < book_path_len; i++) {
923 ret = media_info_get_media_from_db_by_path(book_path_list[i], &media);
924 if (ret != MEDIA_CONTENT_ERROR_NONE)
927 content_debug("===============================");
928 content_debug("[%d] %s", i, book_path_list[i]);
929 content_debug("===============================");
930 media_info_get_title(media, &s_value);
931 content_debug("Title : %s", s_value);
935 ret = media_info_get_book(media, &book);
936 if (ret != MEDIA_CONTENT_ERROR_NONE) {
937 media_info_destroy(media);
941 ret = book_meta_get_author(book, &s_value);
942 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
943 content_debug("Author : %s", s_value);
948 ret = book_meta_get_date(book, &s_value);
949 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
950 content_debug("Date : %s", s_value);
955 content_debug("===============================");
956 ret = book_meta_destroy(book);
957 if (ret != MEDIA_CONTENT_ERROR_NONE)
958 content_error("book_meta_destroy failed");
960 ret = media_info_destroy(media);
961 if (ret != MEDIA_CONTENT_ERROR_NONE)
962 content_error("media_info_destroy failed");
964 g_free(book_path_list[i]);
967 ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
968 content_debug("Search Time [%lld]", ms_time);
970 g_free(book_path_list);
974 int test_disconnect_database(void)
976 int ret = MEDIA_CONTENT_ERROR_NONE;
977 content_debug("\n============DB Disconnection Test============\n\n");
979 ret = media_content_disconnect();
981 if (ret == MEDIA_CONTENT_ERROR_NONE)
982 content_debug("disconnection is success");
984 content_error("disconnection is failed");
989 static int g_total_photo_size = 0;
990 static int g_total_video_size = 0;
991 static int g_total_mp3_size = 0;
992 static int g_total_voice_memo_size = 0;
994 bool dft_cb(media_info_h media, void *user_data)
996 unsigned long long file_size = 0;
997 media_content_type_e media_type = -1;
998 char *mime_type = NULL;
999 int ret = MEDIA_CONTENT_ERROR_NONE;
1004 ret = media_info_get_media_type(media, &media_type);
1005 if (ret != MEDIA_CONTENT_ERROR_NONE)
1006 content_error("media_info_get_media_type failed: %d", ret);
1007 ret = media_info_get_size(media, &file_size);
1008 if (ret != MEDIA_CONTENT_ERROR_NONE)
1009 content_error("media_info_get_size failed: %d", ret);
1010 ret = media_info_get_mime_type(media, &mime_type);
1011 if (ret != MEDIA_CONTENT_ERROR_NONE)
1012 content_error("media_info_get_mime_type failed: %d", ret);
1014 if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
1015 g_total_photo_size += file_size;
1016 else if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
1017 g_total_video_size += file_size;
1018 else if (media_type == MEDIA_CONTENT_TYPE_SOUND)
1019 g_total_voice_memo_size += file_size;
1020 else if (media_type == MEDIA_CONTENT_TYPE_MUSIC) {
1021 if ((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
1022 g_total_mp3_size += file_size;
1024 g_total_voice_memo_size += file_size;
1026 content_debug("invalid media_type");
1028 SAFE_FREE(mime_type);
1036 int ret = MEDIA_CONTENT_ERROR_NONE;
1037 content_debug("\n============DFT_test============\n\n");
1039 filter_h filter = NULL;
1042 /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
1044 ret = media_filter_create(&filter);
1047 content_debug("[Internal Memory]\n");
1048 /*1. Photo ============================================================*/
1049 ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
1052 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1053 content_debug("Photo count = [%d]\n", media_cnt);
1056 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1057 content_debug("Photo size = [%d]\n", g_total_photo_size);
1059 /*2. Video ============================================================*/
1060 ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
1063 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1064 content_debug("Video count = [%d]\n", media_cnt);
1067 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1068 content_debug("Video size = [%d]\n", g_total_video_size);
1070 /*3. MP3 ============================================================*/
1071 ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
1074 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1075 content_debug("MP3 count = [%d]\n", media_cnt);
1078 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1079 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
1081 /*4. Voice Memo ============================================================*/
1082 ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
1084 /*Get Voice Memo Count*/
1085 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1086 content_debug("Voice Memo count = [%d]\n", media_cnt);
1088 /*Get Voice Memo Size*/
1089 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1090 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
1092 g_total_photo_size = 0;
1093 g_total_video_size = 0;
1094 g_total_mp3_size = 0;
1095 g_total_voice_memo_size = 0;
1098 content_debug("\n[External Memory]\n");
1099 /*1. Photo ============================================================*/
1100 ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
1103 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1104 content_debug("Photo count = [%d]\n", media_cnt);
1107 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1108 content_debug("Photo size = [%d]\n", g_total_photo_size);
1110 /*2. Video ============================================================*/
1111 ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
1114 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1115 content_debug("Video count = [%d]\n", media_cnt);
1118 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1119 content_debug("Video size = [%d]\n", g_total_video_size);
1121 /*3. MP3 ============================================================*/
1122 ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
1125 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1126 content_debug("MP3 count = [%d]\n", media_cnt);
1129 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1130 content_debug("MP3 size = [%d]\n", g_total_mp3_size);
1132 /*4. Voice Memo ============================================================*/
1133 ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
1135 /*Get Voice Memo Count*/
1136 ret = media_info_get_media_count_from_db(filter, &media_cnt);
1137 content_debug("Voice Memo count = [%d]\n", media_cnt);
1139 /*Get Voice Memo Size*/
1140 ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
1141 content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
1142 ret = media_filter_destroy(filter);
1147 void insert_batch_cb(media_content_error_e error, void * user_data)
1149 content_debug("media_info_insert_batch_to_db completed!\n");
1152 int test_batch_operations()
1156 char *file_list[10];
1158 for (i = 0; i < 10; i++) {
1159 file_list[i] = g_strdup_printf("%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), i+1);
1160 content_debug("File : %s\n", file_list[i]);
1163 ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL);
1164 if (ret != MEDIA_CONTENT_ERROR_NONE)
1165 content_error("media_info_insert_batch_to_db failed : %d\n", ret);
1167 for (i = 0; i < 10; i++)
1168 g_free(file_list[i]);
1173 void _scan_cb(media_content_error_e err, void *user_data)
1175 content_debug("scan callback is called : %d\n", err);
1176 g_main_loop_quit(g_loop);
1181 int test_scan_file()
1185 const char *file_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
1186 ret = media_content_scan_file(file_path);
1187 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1188 content_error("Fail to media_content_scan_file : %d", ret);
1195 gboolean test_scan_dir_start(gpointer data)
1199 const char *dir_path = tzplatform_getenv(TZ_USER_CONTENT);
1201 ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL);
1203 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1204 content_error("Fail to test_scan_dir_start : %d", ret);
1211 gboolean cancel_scan_dir_start(gpointer data)
1213 int ret = MEDIA_CONTENT_ERROR_NONE;
1215 const char *dir_path = tzplatform_getenv(TZ_USER_IMAGES);
1217 ret = media_content_cancel_scan_folder(dir_path);
1219 if (ret == MEDIA_CONTENT_ERROR_NONE)
1220 content_debug("media_content_cancel_scan_folder is success");
1222 content_error("media_content_cancel_scan_folder is failed");
1227 int test_scan_dir(int cancel)
1229 GSource *source = NULL;
1230 GMainContext *context = NULL;
1232 g_loop = g_main_loop_new(NULL, FALSE);
1233 context = g_main_loop_get_context(g_loop);
1234 source = g_idle_source_new();
1235 g_source_set_callback(source, test_scan_dir_start, NULL, NULL);
1236 g_source_attach(source, context);
1239 GSource *cancel_src = NULL;
1240 cancel_src = g_idle_source_new();
1241 g_source_set_callback(cancel_src, cancel_scan_dir_start, NULL, NULL);
1242 g_source_attach(cancel_src, context);
1245 g_main_loop_run(g_loop);
1246 g_main_loop_unref(g_loop);
1251 void _noti_cb(media_content_error_e error,
1253 media_content_db_update_item_type_e update_item,
1254 media_content_db_update_type_e update_type,
1255 media_content_type_e media_type,
1262 content_debug("noti success! : %d\n", error);
1264 content_debug("error occurred! : %d\n", error);
1266 content_debug("Noti from PID(%d)\n", pid);
1268 if (update_item == MEDIA_ITEM_FILE)
1269 content_debug("Noti item : MEDIA_ITEM_FILE\n");
1270 else if (update_item == MEDIA_ITEM_DIRECTORY)
1271 content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n");
1273 if (update_type == MEDIA_CONTENT_INSERT)
1274 content_debug("Noti type : MEDIA_CONTENT_INSERT\n");
1275 else if (update_type == MEDIA_CONTENT_DELETE)
1276 content_debug("Noti type : MEDIA_CONTENT_DELETE\n");
1277 else if (update_type == MEDIA_CONTENT_UPDATE)
1278 content_debug("Noti type : MEDIA_CONTENT_UPDATE\n");
1280 content_debug("content type : %d\n", media_type);
1283 content_debug("path : %s\n", path);
1285 content_debug("path not\n");
1288 content_debug("uuid : %s\n", uuid);
1290 content_debug("uuid not\n");
1293 content_debug("mime_type : %s\n", mime_type);
1295 content_debug("mime not\n");
1297 if (user_data) content_debug("String : %s\n", (char *)user_data);
1302 void _noti_cb_2(media_content_error_e error,
1304 media_content_db_update_item_type_e update_item,
1305 media_content_db_update_type_e update_type,
1306 media_content_type_e media_type,
1313 content_debug("noti_2 success! : %d\n", error);
1315 content_debug("error occurred! : %d\n", error);
1317 content_debug("Noti_2 from PID(%d)\n", pid);
1319 g_main_loop_quit(g_loop);
1323 static media_content_noti_h noti_h;
1324 static media_content_noti_h noti_h_2;
1326 gboolean _send_noti_operations(gpointer data)
1328 int ret = MEDIA_CONTENT_ERROR_NONE;
1330 /* First of all, noti subscription */
1331 char *user_str = strdup("hi");
1332 media_content_add_db_updated_cb(_noti_cb, (void*)user_str, ¬i_h);
1333 media_content_add_db_updated_cb(_noti_cb_2, (void*)user_str, ¬i_h_2);
1335 /* media_info_insert_to_db */
1336 media_info_h media_item = NULL;
1337 const char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
1339 ret = media_info_insert_to_db(path, &media_item);
1340 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1341 content_error("media_info_insert_to_db failed : %d", ret);
1342 media_info_destroy(media_item);
1346 content_debug("media_info_insert_to_db success");
1348 media_content_remove_db_updated_cb(noti_h);
1350 media_info_destroy(media_item);
1357 int ret = MEDIA_CONTENT_ERROR_NONE;
1358 GSource *source = NULL;
1359 GMainContext *context = NULL;
1361 g_loop = g_main_loop_new(NULL, FALSE);
1362 context = g_main_loop_get_context(g_loop);
1363 source = g_idle_source_new();
1364 g_source_set_callback(source, _send_noti_operations, NULL, NULL);
1365 g_source_attach(source, context);
1367 g_main_loop_run(g_loop);
1368 g_main_loop_unref(g_loop);
1370 test_filter_destroy();
1371 media_content_remove_db_updated_cb(noti_h_2);
1375 #ifdef _USE_TVPD_MODE
1376 filter_h g_tv_filter = NULL;
1378 int test_tv_filter_create(void)
1380 content_debug("\n============Filter Create============\n\n");
1382 int ret = MEDIA_CONTENT_ERROR_NONE;
1384 ret = media_filter_create(&g_tv_filter);
1386 ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
1388 ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
1393 int test_tv_filter_destroy(void)
1395 content_debug("\n============Filter Destroy============\n\n");
1397 int ret = MEDIA_CONTENT_ERROR_NONE;
1399 ret = media_filter_destroy(g_tv_filter);
1404 bool pvr_item_cb(media_pvr_h pvr, void *user_data)
1406 int ret = MEDIA_CONTENT_ERROR_NONE;
1407 char *c_value = NULL;
1409 bool b_value = false;
1410 unsigned long long l_value = 0;
1413 content_debug("NO Item");
1417 ret = media_pvr_get_media_id(pvr, &c_value);
1418 if (ret != MEDIA_CONTENT_ERROR_NONE)
1419 content_error("Fail to media_pvr_get_media_id");
1420 content_debug("media_id [%s]", c_value);
1423 ret = media_pvr_get_channel_name(pvr, &c_value);
1424 if (ret != MEDIA_CONTENT_ERROR_NONE)
1425 content_error("Fail to media_pvr_get_channel_name");
1426 content_debug("channel_name [%s]", c_value);
1429 ret = media_pvr_get_program_title(pvr, &c_value);
1430 if (ret != MEDIA_CONTENT_ERROR_NONE)
1431 content_error("Fail to media_pvr_get_program_title");
1432 content_debug("program_title [%s]", c_value);
1435 ret = media_pvr_get_program_crid(pvr, &c_value);
1436 if (ret != MEDIA_CONTENT_ERROR_NONE)
1437 content_error("Fail to media_pvr_get_program_crid");
1438 content_debug("program_crid [%s]", c_value);
1441 ret = media_pvr_get_guidance(pvr, &c_value);
1442 if (ret != MEDIA_CONTENT_ERROR_NONE)
1443 content_error("Fail to media_pvr_get_guidance");
1444 content_debug("guidance [%s]", c_value);
1447 ret = media_pvr_get_synopsis(pvr, &c_value);
1448 if (ret != MEDIA_CONTENT_ERROR_NONE)
1449 content_error("Fail to media_pvr_get_synopsis");
1450 content_debug("synopsis [%s]", c_value);
1453 ret = media_pvr_get_genre(pvr, &c_value);
1454 if (ret != MEDIA_CONTENT_ERROR_NONE)
1455 content_error("Fail to media_pvr_get_synopsis");
1456 content_debug("genre [%s]", c_value);
1459 ret = media_pvr_get_language(pvr, &c_value);
1460 if (ret != MEDIA_CONTENT_ERROR_NONE)
1461 content_error("Fail to media_pvr_get_language");
1462 content_debug("language [%s]", c_value);
1465 ret = media_pvr_get_path(pvr, &c_value);
1466 if (ret != MEDIA_CONTENT_ERROR_NONE)
1467 content_error("Fail to media_pvr_get_path");
1468 content_debug("path [%s]", c_value);
1471 ret = media_pvr_get_storage_id(pvr, &c_value);
1472 if (ret != MEDIA_CONTENT_ERROR_NONE)
1473 content_error("Fail to media_pvr_get_storage_id");
1474 content_debug("storage_id [%s]", c_value);
1477 ret = media_pvr_get_size(pvr, &l_value);
1478 if (ret != MEDIA_CONTENT_ERROR_NONE)
1479 content_error("Fail to media_pvr_get_size");
1480 content_debug("size [%lld]", l_value);
1482 ret = media_pvr_get_timezone(pvr, &i_value);
1483 if (ret != MEDIA_CONTENT_ERROR_NONE)
1484 content_error("Fail to media_pvr_get_timezone");
1485 content_debug("timezone [%d]", i_value);
1487 ret = media_pvr_get_ptc(pvr, &i_value);
1488 if (ret != MEDIA_CONTENT_ERROR_NONE)
1489 content_error("Fail to media_pvr_get_ptc");
1490 content_debug("ptc [%d]", i_value);
1492 ret = media_pvr_get_major(pvr, &i_value);
1493 if (ret != MEDIA_CONTENT_ERROR_NONE)
1494 content_error("Fail to media_pvr_get_major");
1495 content_debug("[%d]", i_value);
1497 ret = media_pvr_get_minor(pvr, &i_value);
1498 if (ret != MEDIA_CONTENT_ERROR_NONE)
1499 content_error("Fail to media_pvr_get_minor");
1500 content_debug("minor [%d]", i_value);
1502 ret = media_pvr_get_channel_type(pvr, &i_value);
1503 if (ret != MEDIA_CONTENT_ERROR_NONE)
1504 content_error("Fail to media_pvr_get_channel_type");
1505 content_debug("channel_type [%d]", i_value);
1507 ret = media_pvr_get_program_num(pvr, &i_value);
1508 if (ret != MEDIA_CONTENT_ERROR_NONE)
1509 content_error("Fail to media_pvr_get_program_num");
1510 content_debug("program_num [%d]", i_value);
1512 unsigned int ui_value = 0;
1513 ret = media_pvr_get_service_profile(pvr, &ui_value);
1514 if (ret != MEDIA_CONTENT_ERROR_NONE)
1515 content_error("Fail to media_pvr_get_service_profile");
1516 content_debug("service_profile [%u]", ui_value);
1518 ret = media_pvr_get_duration(pvr, &i_value);
1519 if (ret != MEDIA_CONTENT_ERROR_NONE)
1520 content_error("Fail to media_pvr_get_duration");
1521 content_debug("duration [%d]", i_value);
1523 ret = media_pvr_get_embargo_time(pvr, &i_value);
1524 if (ret != MEDIA_CONTENT_ERROR_NONE)
1525 content_error("Fail to media_pvr_get_embargo_time");
1526 content_debug("embargo_time [%d]", i_value);
1528 ret = media_pvr_get_expiry_time(pvr, &i_value);
1529 if (ret != MEDIA_CONTENT_ERROR_NONE)
1530 content_error("Fail to media_pvr_get_expiry_time");
1531 content_debug("expiry_time [%d]", i_value);
1533 ret = media_pvr_get_parental_rating(pvr, &i_value);
1534 if (ret != MEDIA_CONTENT_ERROR_NONE)
1535 content_error("Fail to media_pvr_get_parental_rating");
1536 content_debug("parental_rating [%d]", i_value);
1538 ret = media_pvr_get_start_time(pvr, &i_value);
1539 if (ret != MEDIA_CONTENT_ERROR_NONE)
1540 content_error("Fail to media_pvr_get_start_time");
1541 content_debug("start_time [%d]", i_value);
1543 ret = media_pvr_get_program_start_time(pvr, &i_value);
1544 if (ret != MEDIA_CONTENT_ERROR_NONE)
1545 content_error("Fail to media_pvr_get_program_start_time");
1546 content_debug("program_start_time [%d]", i_value);
1548 ret = media_pvr_get_program_end_time(pvr, &i_value);
1549 if (ret != MEDIA_CONTENT_ERROR_NONE)
1550 content_error("Fail to media_pvr_get_program_end_time");
1551 content_debug("program_end_time [%d]", i_value);
1553 ret = media_pvr_get_program_date(pvr, &i_value);
1554 if (ret != MEDIA_CONTENT_ERROR_NONE)
1555 content_error("Fail to media_pvr_get_program_date");
1556 content_debug("program_date [%d]", i_value);
1558 ret = media_pvr_get_timer_record(pvr, &b_value);
1559 if (ret != MEDIA_CONTENT_ERROR_NONE)
1560 content_error("Fail to media_pvr_get_timer_record");
1561 content_debug("timer_record [%d]", b_value);
1563 ret = media_pvr_get_series_record(pvr, &b_value);
1564 if (ret != MEDIA_CONTENT_ERROR_NONE)
1565 content_error("Fail to media_pvr_get_series_record");
1566 content_debug("series_record [%d]", b_value);
1568 ret = media_pvr_get_hd(pvr, &i_value);
1569 if (ret != MEDIA_CONTENT_ERROR_NONE)
1570 content_error("Fail to media_pvr_get_hd");
1571 content_debug("hd [%d]", i_value);
1573 ret = media_pvr_get_subtitle(pvr, &b_value);
1574 if (ret != MEDIA_CONTENT_ERROR_NONE)
1575 content_error("Fail to media_pvr_get_subtitle");
1576 content_debug("subtitle [%d]", b_value);
1578 ret = media_pvr_get_ttx(pvr, &b_value);
1579 if (ret != MEDIA_CONTENT_ERROR_NONE)
1580 content_error("Fail to media_pvr_get_ttx");
1581 content_debug("ttx [%d]", b_value);
1583 ret = media_pvr_get_ad(pvr, &b_value);
1584 if (ret != MEDIA_CONTENT_ERROR_NONE)
1585 content_error("Fail to media_pvr_get_ad");
1586 content_debug("ad [%d]", b_value);
1588 ret = media_pvr_get_hard_of_hearing_radio(pvr, &b_value);
1589 if (ret != MEDIA_CONTENT_ERROR_NONE)
1590 content_error("Fail to media_pvr_get_hard_of_hearing_radio");
1591 content_debug("hard_of_hearing_radio [%d]", b_value);
1593 ret = media_pvr_get_data_service(pvr, &b_value);
1594 if (ret != MEDIA_CONTENT_ERROR_NONE)
1595 content_error("Fail to media_pvr_get_data_service");
1596 content_debug("data_service [%d]", b_value);
1598 ret = media_pvr_get_content_lock(pvr, &b_value);
1599 if (ret != MEDIA_CONTENT_ERROR_NONE)
1600 content_error("Fail to media_pvr_get_content_lock");
1601 content_debug("content_lock [%d]", b_value);
1603 ret = media_pvr_get_content_watch(pvr, &b_value);
1604 if (ret != MEDIA_CONTENT_ERROR_NONE)
1605 content_error("Fail to media_pvr_get_content_watch");
1606 content_debug("content_watch [%d]", b_value);
1608 ret = media_pvr_get_has_audio_only(pvr, &b_value);
1609 if (ret != MEDIA_CONTENT_ERROR_NONE)
1610 content_error("Fail to media_pvr_get_has_audio_only");
1611 content_debug("has_audio_only [%d]", b_value);
1613 ret = media_pvr_get_is_local_record(pvr, &b_value);
1614 if (ret != MEDIA_CONTENT_ERROR_NONE)
1615 content_error("Fail to media_pvr_get_is_local_record");
1616 content_debug("is_local_record [%d]", b_value);
1618 ret = media_pvr_get_resolution(pvr, (media_pvr_resolution_e*)&i_value);
1619 if (ret != MEDIA_CONTENT_ERROR_NONE)
1620 content_error("Fail to media_pvr_get_resolution");
1621 content_debug("resolution [%d]", i_value);
1623 ret = media_pvr_get_aspectratio(pvr, (media_pvr_aspectratio_e*)&i_value);
1624 if (ret != MEDIA_CONTENT_ERROR_NONE)
1625 content_error("Fail to media_pvr_get_aspectratio");
1626 content_debug("aspectratio [%d]", i_value);
1628 ret = media_pvr_get_highlight(pvr, &b_value);
1629 if (ret != MEDIA_CONTENT_ERROR_NONE)
1630 content_error("Fail to media_pvr_get_highlight");
1631 content_debug("highlight [%d]", b_value);
1639 int ret = MEDIA_CONTENT_ERROR_NONE;
1640 int media_count = 0;
1642 content_debug("\n============PVR Test============\n\n");
1644 test_tv_filter_create();
1646 ret = media_pvr_get_media_count_from_db(g_tv_filter, &media_count);
1647 if (ret != MEDIA_CONTENT_ERROR_NONE)
1648 content_error("media_pvr_get_media_count_from_db failed: %d", ret);
1650 content_debug("media_count : [%d]", media_count);
1652 ret = media_pvr_foreach_media_from_db(g_tv_filter, pvr_item_cb, NULL);
1653 if (ret != MEDIA_CONTENT_ERROR_NONE)
1654 content_error("media_pvr_foreach_media_from_db is failed");
1656 test_tv_filter_destroy();
1661 int test_pvr_update_db(void)
1663 int ret = MEDIA_CONTENT_ERROR_NONE;
1664 media_pvr_h pvr = NULL;
1666 ret = media_pvr_get_pvr_from_db("ff9b5a9a-a7b4-47f4-8255-84e007e25f13", &pvr);
1667 if (ret != MEDIA_CONTENT_ERROR_NONE)
1668 content_error("media_pvr_get_pvr_from_db failed: %d", ret);
1670 ret = media_pvr_set_content_lock(pvr, TRUE);
1671 if (ret != MEDIA_CONTENT_ERROR_NONE)
1672 content_error("Fail to media_pvr_set_content_lock");
1674 ret = media_pvr_set_content_watch(pvr, TRUE);
1675 if (ret != MEDIA_CONTENT_ERROR_NONE)
1676 content_error("Fail to media_pvr_set_content_watch");
1678 ret = media_pvr_set_program_title(pvr, "TEST TITLE");
1679 if (ret != MEDIA_CONTENT_ERROR_NONE)
1680 content_error("Fail to media_pvr_set_program_title");
1682 ret = media_pvr_set_highlight(pvr, TRUE);
1683 if (ret != MEDIA_CONTENT_ERROR_NONE)
1684 content_error("Fail to media_pvr_set_highlight");
1686 ret = media_pvr_update_to_db(pvr);
1687 if (ret != MEDIA_CONTENT_ERROR_NONE)
1688 content_error("Fail to media_pvr_update_to_db");
1691 media_pvr_destroy(pvr);
1697 int main(int argc, char *argv[])
1699 int ret = MEDIA_CONTENT_ERROR_NONE;
1701 content_debug("--- content manager test start ---\n\n");
1703 ret = test_connect_database();
1704 if (ret != MEDIA_CONTENT_ERROR_NONE)
1705 return MEDIA_CONTENT_ERROR_NONE;
1706 #ifdef _USE_TVPD_MODE
1709 test_pvr_update_db();
1716 ret = test_ebook_text_finder(argv[1]);
1717 if (ret != MEDIA_CONTENT_ERROR_NONE)
1722 if (ret != MEDIA_CONTENT_ERROR_NONE)
1725 ret = test_gallery_scenario();
1726 if (ret != MEDIA_CONTENT_ERROR_NONE)
1729 ret = test_get_all_music_files();
1730 if (ret != MEDIA_CONTENT_ERROR_NONE)
1733 ret = test_media_info_operation();
1734 if (ret != MEDIA_CONTENT_ERROR_NONE)
1737 ret = test_folder_operation();
1738 if (ret != MEDIA_CONTENT_ERROR_NONE)
1741 ret = test_album_list();
1742 if (ret != MEDIA_CONTENT_ERROR_NONE)
1745 ret = test_group_operation();
1746 if (ret != MEDIA_CONTENT_ERROR_NONE)
1749 ret = test_update_operation();
1750 if (ret != MEDIA_CONTENT_ERROR_NONE)
1753 ret = test_insert();
1754 if (ret != MEDIA_CONTENT_ERROR_NONE)
1758 if (ret != MEDIA_CONTENT_ERROR_NONE)
1762 ret = test_create_thumbnail(argv[1]);
1763 if (ret != MEDIA_CONTENT_ERROR_NONE)
1768 if (ret != MEDIA_CONTENT_ERROR_NONE)
1771 ret = test_batch_operations();
1772 if (ret != MEDIA_CONTENT_ERROR_NONE)
1773 return MEDIA_CONTENT_ERROR_NONE;
1775 ret = test_scan_file();
1776 if (ret != MEDIA_CONTENT_ERROR_NONE)
1777 return MEDIA_CONTENT_ERROR_NONE;
1779 ret = test_scan_dir(true);
1780 if (ret != MEDIA_CONTENT_ERROR_NONE)
1781 return MEDIA_CONTENT_ERROR_NONE;
1784 if (ret != MEDIA_CONTENT_ERROR_NONE)
1785 return MEDIA_CONTENT_ERROR_NONE;
1788 ret = test_disconnect_database();
1789 if (ret != MEDIA_CONTENT_ERROR_NONE)
1792 content_debug("--- content manager test end ---\n");