37cb46b7c5c66231f60af908062cd6ac9cac25e1
[platform/core/api/media-content.git] / test / media-content_test.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <sys/time.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <media_content.h>
22 #include <media_info_private.h>
23 #include <dlog.h>
24 #include <pthread.h>
25 #include <glib.h>
26 #include <tzplatform_config.h>
27 #include <media_content_internal.h>
28
29
30 static filter_h g_filter = NULL;
31 static filter_h g_filter_g = NULL;      /*filter for group like folder, tag, playlist, album, year ... */
32
33 static GMainLoop *g_loop = NULL;
34 static int g_cnt = 0;
35 static int g_media_cnt = 0;
36
37 #define test_audio_id "3304285f-1070-41af-8b4e-f0086cc768f3"
38 #define test_video_id "53c43e7e-53d2-4194-80a6-55d5dcde0def"
39 #define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197"
40
41 static void get_audio_meta(media_info_h media)
42 {
43         audio_meta_h audio = NULL;
44         char *c_value = NULL;
45         int i_value = 0;
46
47         content_debug("=== audio meta ===");
48         if (media_info_get_audio(media, &audio) != MEDIA_CONTENT_ERROR_NONE)
49                 return;
50
51         if (audio_meta_get_media_id(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
52                 content_debug("audio_id : [%s]", c_value);
53                 SAFE_FREE(c_value);
54         }
55
56         if (audio_meta_get_album(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
57                 content_debug("album : [%s]", c_value);
58                 SAFE_FREE(c_value);
59         }
60
61         if (audio_meta_get_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
62                 content_debug("artist : [%s]", c_value);
63                 SAFE_FREE(c_value);
64         }
65
66         if (audio_meta_get_album_artist(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
67                 content_debug("album artist : [%s]", c_value);
68                 SAFE_FREE(c_value);
69         }
70
71         if (audio_meta_get_genre(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
72                 content_debug("genre : [%s]", c_value);
73                 SAFE_FREE(c_value);
74         }
75
76         if (audio_meta_get_composer(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
77                 content_debug("composer : [%s]", c_value);
78                 SAFE_FREE(c_value);
79         }
80
81         if (audio_meta_get_year(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
82                 content_debug("year : [%s]", c_value);
83                 SAFE_FREE(c_value);
84         }
85
86         if (audio_meta_get_recorded_date(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
87                 content_debug("recorded date : [%s]", c_value);
88                 SAFE_FREE(c_value);
89         }
90
91         if (audio_meta_get_copyright(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
92                 content_debug("copyright : [%s]", c_value);
93                 SAFE_FREE(c_value);
94         }
95
96         if (audio_meta_get_track_num(audio, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
97                 content_debug("track number : [%s]", c_value);
98                 SAFE_FREE(c_value);
99         }
100
101         if (audio_meta_get_bit_rate(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
102                 content_debug("bitrate : [%d]", i_value);
103
104         if (audio_meta_get_sample_rate(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
105                 content_debug("samplerate : [%d]", i_value);
106
107         if (audio_meta_get_channel(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
108                 content_debug("channel : [%d]", i_value);
109
110         if (audio_meta_get_duration(audio, &i_value) == MEDIA_CONTENT_ERROR_NONE)
111                 content_debug("duration : [%d]", i_value);
112
113         audio_meta_destroy(audio);
114 }
115
116 static void get_video_meta(media_info_h media)
117 {
118         video_meta_h video = NULL;
119         char *c_value = NULL;
120         int i_value = 0;
121
122         content_debug("=== video meta ===");
123         if (media_info_get_video(media, &video) != MEDIA_CONTENT_ERROR_NONE)
124                 return;
125
126         if (video_meta_get_media_id(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
127                 content_debug("video_id : [%s]", c_value);
128                 SAFE_FREE(c_value);
129         }
130
131         if (video_meta_get_album(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
132                 content_debug("album : [%s]", c_value);
133                 SAFE_FREE(c_value);
134         }
135
136         if (video_meta_get_artist(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
137                 content_debug("artist : [%s]", c_value);
138                 SAFE_FREE(c_value);
139         }
140
141         if (video_meta_get_album_artist(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
142                 content_debug("album artist : [%s]", c_value);
143                 SAFE_FREE(c_value);
144         }
145
146         if (video_meta_get_genre(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
147                 content_debug("genre : [%s]", c_value);
148                 SAFE_FREE(c_value);
149         }
150
151         if (video_meta_get_composer(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
152                 content_debug("composer : [%s]", c_value);
153                 SAFE_FREE(c_value);
154         }
155
156         if (video_meta_get_year(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
157                 content_debug("year : [%s]", c_value);
158                 SAFE_FREE(c_value);
159         }
160
161         if (video_meta_get_recorded_date(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
162                 content_debug("recorded date : [%s]", c_value);
163                 SAFE_FREE(c_value);
164         }
165
166         if (video_meta_get_copyright(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
167                 content_debug("copyright : [%s]", c_value);
168                 SAFE_FREE(c_value);
169         }
170
171         if (video_meta_get_track_num(video, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
172                 content_debug("track num : [%s]", c_value);
173                 SAFE_FREE(c_value);
174         }
175
176         if (video_meta_get_bit_rate(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
177                 content_debug("bitrate : [%d]", i_value);
178
179         if (video_meta_get_duration(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
180                 content_debug("duration : [%d]", i_value);
181
182         if (video_meta_get_width(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
183                 content_debug("width : [%d]", i_value);
184
185         if (video_meta_get_height(video, &i_value) == MEDIA_CONTENT_ERROR_NONE)
186                 content_debug("height : [%d]", i_value);
187
188         video_meta_destroy(video);
189 }
190
191 static void get_image_meta(media_info_h media)
192 {
193         image_meta_h image = NULL;
194         char *c_value = NULL;
195         int i_value = 0;
196         media_content_orientation_e orientation;
197
198         content_debug("=== image meta ===");
199         if (media_info_get_image(media, &image) != MEDIA_CONTENT_ERROR_NONE)
200                 return;
201
202         if (image_meta_get_width(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
203                 content_debug("width : [%d]", i_value);
204
205         if (image_meta_get_height(image, &i_value) == MEDIA_CONTENT_ERROR_NONE)
206                 content_debug("height : [%d]", i_value);
207
208         if (image_meta_get_orientation(image, &orientation) == MEDIA_CONTENT_ERROR_NONE)
209                 content_debug("orientation : [%d]", orientation);
210
211         if (image_meta_get_date_taken(image, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
212                 content_debug("datetaken : [%s]", c_value);
213                 SAFE_FREE(c_value);
214         }
215
216         image_meta_destroy(image);
217 }
218
219 static void get_book_meta(media_info_h media)
220 {
221         book_meta_h book = NULL;
222         char *c_value = NULL;
223
224         content_debug("=== book meta ===");
225         if (media_info_get_book(media, &book) != MEDIA_CONTENT_ERROR_NONE)
226                 return;
227
228         if (book_meta_get_media_id(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
229                 content_debug("media_id : [%s]", c_value);
230                 SAFE_FREE(c_value);
231         }
232
233         if (book_meta_get_author(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
234                 content_debug("author : [%s]", c_value);
235                 SAFE_FREE(c_value);
236         }
237
238         if (book_meta_get_date(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
239                 content_debug("date : [%s]", c_value);
240                 SAFE_FREE(c_value);
241         }
242
243         if (book_meta_get_publisher(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
244                 content_debug("publisher : [%s]", c_value);
245                 SAFE_FREE(c_value);
246         }
247
248         if (book_meta_get_subject(book, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
249                 content_debug("subject : [%s]", c_value);
250                 SAFE_FREE(c_value);
251         }
252
253         book_meta_destroy(book);
254 }
255
256 static void get_album_meta(media_album_h album)
257 {
258         char *c_value = NULL;
259         int i_value = 0;
260
261         content_debug("=== album meta ===");
262         if (media_album_get_album_id(album, &i_value) == MEDIA_CONTENT_ERROR_NONE)
263                 content_debug("album id : [%d]", i_value);
264
265         if (media_album_get_name(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
266                 content_debug("album name : [%s]", c_value);
267                 SAFE_FREE(c_value);
268         }
269
270         if (media_album_get_artist(album, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
271                 content_debug("album artist : [%s]", c_value);
272                 SAFE_FREE(c_value);
273         }
274 }
275
276 static void get_bookmark_meta(media_bookmark_h bookmark)
277 {
278         char *c_value = NULL;
279         int i_value = 0;
280         time_t time = 0;
281
282         content_debug("=== bookmark meta ===");
283         if (media_bookmark_get_bookmark_id(bookmark, &i_value) == MEDIA_CONTENT_ERROR_NONE)
284                 content_debug("bookmark_id : %d", i_value);
285
286         if (media_bookmark_get_thumbnail_path(bookmark, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
287                 content_debug("bookmark thumbnail_path : %s", c_value);
288                 SAFE_FREE(c_value);
289         }
290
291         if (media_bookmark_get_marked_time(bookmark, &time) == MEDIA_CONTENT_ERROR_NONE)
292                 content_debug("bookmark marked_time : %ld", time);
293
294         if (media_bookmark_get_name(bookmark, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
295                 content_debug("bookmark name : %s", c_value);
296                 SAFE_FREE(c_value);
297         }
298 }
299
300 static void get_tag_meta(media_tag_h tag)
301 {
302         char *c_value = NULL;
303         int i_value = 0;
304
305         content_debug("=== tag meta ===");
306         if (media_tag_get_tag_id(tag, &i_value) == MEDIA_CONTENT_ERROR_NONE)
307                 content_debug("tag_id : %d", i_value);
308
309         if (media_tag_get_name(tag, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
310                 content_debug("tag_name : %s", c_value);
311                 SAFE_FREE(c_value);
312         }
313 }
314
315 static void get_face_meta(media_face_h face)
316 {
317         char *c_value = NULL;
318         unsigned int rect_x = 0;
319         unsigned int rect_y = 0;
320         unsigned int rect_w = 0;
321         unsigned int rect_h = 0;
322         media_content_orientation_e orientation = 0;
323
324         content_debug("=== face meta ===");
325         if (media_face_get_face_id(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
326                 content_debug("face_id : %s", c_value);
327                 SAFE_FREE(c_value);
328         }
329
330         if (media_face_get_media_id(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
331                 content_debug("media_id : %s", c_value);
332                 SAFE_FREE(c_value);
333         }
334
335         if (media_face_get_face_rect(face, &rect_x, &rect_y, &rect_w, &rect_h) == MEDIA_CONTENT_ERROR_NONE)
336                 content_debug("face_rect x[%d] y[%d] w[%d] h[%d]", rect_x, rect_y, rect_w, rect_h);
337
338         if (media_face_get_orientation(face, &orientation) == MEDIA_CONTENT_ERROR_NONE)
339                 content_debug("orientation : %d", orientation);
340
341         if (media_face_get_tag(face, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
342                 content_debug("tag : %s", c_value);
343                 SAFE_FREE(c_value);
344         }
345 }
346
347 static void get_folder_meta(media_folder_h folder, char **folder_id)
348 {
349         char *c_value = NULL;
350
351         content_debug("=== folder meta ===");
352         if (media_folder_get_folder_id(folder, &c_value) != MEDIA_CONTENT_ERROR_NONE) {
353                 content_debug("folder_id : %s", c_value);
354                 *folder_id = c_value;
355         }
356
357         if (media_folder_get_path(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
358                 content_debug("folder_path : %s", c_value);
359                 SAFE_FREE(c_value);
360         }
361
362         if (media_folder_get_name(folder, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
363                 content_debug("folder_name : %s", c_value);
364                 SAFE_FREE(c_value);
365         }
366 }
367
368 static void get_media_meta(media_info_h media)
369 {
370         char *c_value = NULL;
371         int i_value = 0;
372         time_t t_value = 0;
373         bool b_value = false;
374         unsigned long long size = 0;
375         media_content_type_e media_type = 0;
376
377         content_debug("=== media meta ===");
378         if (media_info_get_media_type(media, &media_type) == MEDIA_CONTENT_ERROR_NONE)
379                 content_debug("media_type : [%d]", media_type);
380
381         if (media_info_get_media_id(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
382                 content_debug("media_id : [%s]", c_value);
383                 SAFE_FREE(c_value);
384         }
385
386         if (media_info_get_file_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
387                 content_debug("file_path : [%s]", c_value);
388                 SAFE_FREE(c_value);
389         }
390
391         if (media_info_get_display_name(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
392                 content_debug("display_name : [%s]", c_value);
393                 SAFE_FREE(c_value);
394         }
395
396         if (media_info_get_mime_type(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
397                 content_debug("mime_type : [%s]", c_value);
398                 SAFE_FREE(c_value);
399         }
400
401         if (media_info_get_thumbnail_path(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
402                 content_debug("thumbnail_path : [%s]", c_value);
403                 SAFE_FREE(c_value);
404         }
405
406         if (media_info_get_description(media, &c_value) == MEDIA_CONTENT_ERROR_NONE) {
407                 content_debug("description : [%s]", c_value);
408                 SAFE_FREE(c_value);
409         }
410
411         if (media_info_get_size(media, &size) == MEDIA_CONTENT_ERROR_NONE)
412                 content_debug("size : [%lld]", size);
413
414         if (media_info_get_added_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
415                 content_debug("added_time : [%ld]", t_value);
416
417         if (media_info_get_modified_time(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
418                 content_debug("modified_time : [%ld]", t_value);
419
420         if (media_info_get_timeline(media, &t_value) == MEDIA_CONTENT_ERROR_NONE)
421                 content_debug("timeline : [%ld]", t_value);
422
423         if (media_info_get_rating(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
424                 content_debug("rating : [%d]", i_value);
425
426         if (media_info_get_favorite(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
427                 content_debug("favorite : [%d]", b_value);
428
429         if (media_info_is_drm(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
430                 content_debug("is_drm : [%d]", b_value);
431
432         if (media_info_is_360_content(media, &b_value) == MEDIA_CONTENT_ERROR_NONE)
433                 content_debug("is_360 : [%d]", b_value);
434
435 #ifdef _USE_TVPD_MODE
436         if (media_info_get_stitched_state(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
437                 content_debug("360 stitched : [%d]", i_value);
438
439         if (media_info_get_stitched_engine(media, &i_value) == MEDIA_CONTENT_ERROR_NONE)
440                 content_debug("360 engine : [%d]", i_value);
441 #endif
442
443         if (media_type == MEDIA_CONTENT_TYPE_MUSIC)
444                 get_audio_meta(media);
445
446         if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
447                 get_image_meta(media);
448
449         if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
450                 get_video_meta(media);
451
452         if (media_type == MEDIA_CONTENT_TYPE_BOOK)
453                 get_book_meta(media);
454
455         if (media_type == MEDIA_CONTENT_TYPE_OTHERS)
456                 content_debug("Other type");
457 }
458
459 bool media_item_cb(media_info_h media, void *user_data)
460 {
461         if (!media) {
462                 content_debug("NO Item");
463                 return true;
464         }
465
466         get_media_meta(media);
467
468         return true;
469 }
470
471 bool gallery_folder_list_cb(media_folder_h folder, void *user_data)
472 {
473         media_folder_h new_folder = NULL;
474         media_folder_clone(&new_folder, folder);
475
476         GList **list = (GList**)user_data;
477         *list = g_list_append(*list, new_folder);
478
479         return true;
480 }
481
482 bool gallery_media_item_cb(media_info_h media, void *user_data)
483 {
484         media_info_h new_media = NULL;
485         int ret = MEDIA_CONTENT_ERROR_NONE;
486
487         ret = media_info_clone(&new_media, media);
488
489         if (ret != MEDIA_CONTENT_ERROR_NONE) {
490                 GList **list = (GList**)user_data;
491                 *list = g_list_append(*list, new_media);
492         }
493
494         return true;
495 }
496
497 bool gallery_tag_item_cb(media_tag_h tag, void *user_data)
498 {
499         media_tag_h new_tag = NULL;
500         media_tag_clone(&new_tag, tag);
501
502         GList **list = (GList**)user_data;
503         *list = g_list_append(*list, new_tag);
504
505         return true;
506 }
507
508 bool gallery_bookmarks_cb(media_bookmark_h bookmark, void *user_data)
509 {
510         media_bookmark_h new_bm = NULL;
511         int ret = MEDIA_CONTENT_ERROR_NONE;
512
513         ret = media_bookmark_clone(&new_bm, bookmark);
514         if (ret != MEDIA_CONTENT_ERROR_NONE)
515                 content_error("error media_bookmark_clone : [%d]", ret);
516
517         GList **list = (GList**)user_data;
518         *list = g_list_append(*list, new_bm);
519
520         return true;
521 }
522
523 bool folder_list_cb(media_folder_h folder, void *user_data)
524 {
525         int item_count = 0;
526         char *folder_id = NULL;
527         media_folder_h *_folder = (media_folder_h*)user_data;
528
529         content_debug("===========================");
530         if (folder != NULL) {
531                 if (_folder != NULL)
532                         media_folder_clone(_folder, folder);
533
534                 get_folder_meta(folder, &folder_id);
535
536                 if (media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) {
537                         SAFE_FREE(folder_id);
538                         content_error("[ERROR] media_folder_get_media_count_from_db is failed");
539                         return false;
540                 }
541
542                 if (media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) {
543                         SAFE_FREE(folder_id);
544                         content_error("[ERROR] media_folder_foreach_media_from_db is failed");
545                         return false;
546                 }
547
548                 SAFE_FREE(folder_id);
549                 return true;
550         } else {
551                 return false;
552         }
553
554 }
555
556 bool playlist_list_cb(media_playlist_h playlist, void *user_data)
557 {
558         int ret = MEDIA_CONTENT_ERROR_NONE;
559         int playlist_id = 0;
560         char *playlist_name = NULL;
561         media_playlist_h playlist_h;
562         char *playlist_thumbnail_path = NULL;
563
564         content_debug("playlist_list_cb ======");
565 #if 0
566         GList **list = (GList**)user_data;
567 #endif
568
569         if (playlist == NULL) {
570                 content_debug(" playlist handle is NULL");
571                 return false;
572         }
573
574         ret = media_playlist_get_playlist_id(playlist, &playlist_id);
575         if (ret != MEDIA_CONTENT_ERROR_NONE)
576                 content_error("error media_playlist_get_playlist_id : [%d]", ret);
577
578         content_debug("playlist_id : %d", playlist_id);
579         /* 64bit build issue */
580 #if 0
581         if (user_data != NULL)
582                 *list = g_list_append(*list, (gpointer)playlist_id);
583 #endif
584         ret = media_playlist_get_name(playlist, &playlist_name);
585         if (ret != MEDIA_CONTENT_ERROR_NONE)
586                 content_error("error media_playlist_get_name : [%d]", ret);
587
588         content_debug("playlist_name : %s", playlist_name);
589         SAFE_FREE(playlist_name);
590
591         ret = media_playlist_get_thumbnail_path(playlist, &playlist_thumbnail_path);
592         if (ret != MEDIA_CONTENT_ERROR_NONE)
593                 content_error("error media_playlist_get_thumbnail_path : [%d]", ret);
594
595         content_debug("playlist_thumbnail_path : %s", playlist_thumbnail_path);
596         SAFE_FREE(playlist_thumbnail_path);
597
598         ret = media_playlist_get_playlist_from_db(playlist_id, &playlist_h);
599         if (ret != MEDIA_CONTENT_ERROR_NONE)
600                 content_error("error media_playlist_get_playlist_from_db : [%d]", ret);
601
602         ret = media_playlist_destroy(playlist_h);
603         if (ret != MEDIA_CONTENT_ERROR_NONE)
604                 content_error("error media_playlist_destroy : [%d]", ret);
605
606         return true;
607 }
608
609 bool tag_list_cb(media_tag_h tag, void *user_data)
610 {
611         if (!tag) {
612                 content_debug(" tag handle is NULL");
613                 return false;
614         }
615
616         get_tag_meta(tag);
617
618         return true;
619 }
620
621 bool bookmarks_cb(media_bookmark_h bookmark, void *user_data)
622 {
623         if (bookmark != NULL && user_data != NULL) {
624                 media_bookmark_h new_bookmark;
625
626                 media_bookmark_clone(&new_bookmark, bookmark);
627                 GList **list = (GList**)user_data;
628                 *list = g_list_append(*list, new_bookmark);
629         }
630
631         get_bookmark_meta(bookmark);
632
633         return true;
634 }
635
636 bool album_list_cb(media_album_h album, void *user_data)
637 {
638         int album_id = 0;
639         int media_count = 0;
640         int ret = MEDIA_CONTENT_ERROR_NONE;
641
642         if (album != NULL) {
643                 get_album_meta(album);
644                 media_album_get_album_id(album, &album_id);
645
646                 ret = media_album_get_media_count_from_db(album_id, NULL, &media_count);
647                 if (ret != MEDIA_CONTENT_ERROR_NONE)
648                         content_error("error media_album_get_media_count_from_db : [%d]", ret);
649
650                 content_debug("media_count : [%d]", media_count);
651
652                 ret = media_album_foreach_media_from_db(album_id, NULL, media_item_cb, NULL);
653                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
654                         content_error("error media_album_foreach_media_from_db : [%d]", ret);
655                         return false;
656                 }
657
658         } else {
659                 content_error("album item not Found!!");
660         }
661
662         return true;
663 }
664
665 bool group_list_cb(const char *group_name, void *user_data)
666 {
667         int media_count = 0;
668         int *idx = user_data;
669
670         content_debug("group item : [%s] [%d]", group_name, *idx);
671
672         if (media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
673                 return false;
674
675         content_debug("media_count : [%d]", media_count);
676
677         if (media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
678                 return false;
679
680         return true;
681 }
682
683 bool playlist_item_cb(int playlist_member_id, media_info_h media, void *user_data)
684 {
685         content_debug("playlist_member_id : [%d]", playlist_member_id);
686         /* 64bit build issue */
687 #if 0
688         GList **list = (GList**)user_data;
689
690         *list = g_list_append(*list, (gpointer)playlist_member_id);
691 #endif
692         /*media_item_cb(media, user_data);*/
693
694         return true;
695 }
696
697 int test_filter_create(void)
698 {
699         content_debug("\n============Filter Create============\n\n");
700
701         int ret = MEDIA_CONTENT_ERROR_NONE;
702
703         /* Filter for media */
704         const char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
705
706         ret = media_filter_create(&g_filter);
707
708         /* Set condition and collate
709          * Condition string : You can make where statement of sql.
710          * Colation : You can use collation when comparing.
711          * Ex) In case of FILE_NAME='Samsung' as condition string,
712          *      if you want to compare with NOCASE collation,
713          *      call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
714          *      if you want to compare in case-sensitive,
715          *      call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
716          */
717         ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
718
719         /* Collation of ordering
720          * If you want to get list, which is sorted by NOCASE,
721          * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_NOCASE);
722          * Or,
723          * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
724          */
725         /* Able to set multi column to set order */
726 #if 0
727         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, "MEDIA_MODIFIED_TIME, MEDIA_DISPLAY_NAME", MEDIA_CONTENT_COLLATE_DEFAULT);
728         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
729         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TRACK_NUM_INT, MEDIA_CONTENT_COLLATE_DEFAULT);
730         ret = media_filter_set_storage(g_filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e");
731
732         /* Filter for group */
733         const char *g_condition = "TAG_NAME like \"\%my\%\"";
734         const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
735 #endif
736         ret = media_filter_create(&g_filter_g);
737
738         ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
739
740         return ret;
741 }
742
743 int test_filter_destroy(void)
744 {
745         content_debug("\n============Filter Create============\n\n");
746
747         int ret = MEDIA_CONTENT_ERROR_NONE;
748
749         ret = media_filter_destroy(g_filter);
750
751         return ret;
752 }
753
754 int test_connect_database(void)
755 {
756         int ret = MEDIA_CONTENT_ERROR_NONE;
757
758         content_debug("\n============DB Connection Test============\n\n");
759
760         ret = media_content_connect();
761
762         if (ret == MEDIA_CONTENT_ERROR_NONE)
763                 content_debug("connection is success\n\n");
764         else
765                 content_error("connection is failed\n\n");
766
767         return ret;
768 }
769
770 int test_gallery_scenario(void)
771 {
772         int ret = MEDIA_CONTENT_ERROR_NONE;
773         unsigned int i = 0;
774         filter_h filter = NULL;
775
776         int count;
777         GList *folder_list = NULL;
778         media_folder_h folder_handle = NULL;
779
780         /* First, Get folder list */
781         ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
782         if (ret != MEDIA_CONTENT_ERROR_NONE) {
783                 content_error("media_folder_foreach_folder_from_db failed: %d", ret);
784                 return -1;
785         } else {
786                 content_debug("media_folder_foreach_folder_from_db success!!");
787                 char *folder_id = NULL;
788
789                 for (i = 0; i < g_list_length(folder_list); i++) {
790                         folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
791
792                         get_folder_meta(folder_handle, &folder_id);
793
794                         ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
795                         SAFE_FREE(folder_id);
796                         if (ret != MEDIA_CONTENT_ERROR_NONE) {
797                                 content_error("media_folder_get_media_count_from_db failed: %d", ret);
798                                 return -1;
799                         } else {
800                                 content_debug("media count [%d] : %d", i, count);
801                         }
802                 }
803         }
804
805         /* To check performance */
806         struct timeval start, end;
807         gettimeofday(&start, NULL);
808
809         /* Second, Get all item list */
810         media_info_h media_handle = NULL;
811         GList *all_item_list = NULL;
812
813         media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
814         media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
815         ret = media_filter_create(&filter);
816         if (ret != MEDIA_CONTENT_ERROR_NONE) {
817                 content_error("Fail to create filter");
818                 return ret;
819         }
820         ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
821         if (ret != MEDIA_CONTENT_ERROR_NONE) {
822                 media_filter_destroy(filter);
823                 content_error("Fail to set condition");
824                 return ret;
825         }
826         ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
827         if (ret != MEDIA_CONTENT_ERROR_NONE) {
828                 media_filter_destroy(filter);
829                 content_error("Fail to set order");
830                 return ret;
831         }
832
833         ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
834         if (ret != MEDIA_CONTENT_ERROR_NONE) {
835                 content_error("media_info_foreach_media_from_db failed: %d", ret);
836                 media_filter_destroy(filter);
837                 return -1;
838         } else {
839                 content_debug("media_info_foreach_media_from_db success");
840
841                 for (i = 0; i < g_list_length(all_item_list); i++) {
842                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
843                         get_media_meta(media_handle);
844                 }
845         }
846
847         media_filter_destroy(filter);
848         filter = NULL;
849
850         /* To check performance */
851         gettimeofday(&end, NULL);
852         long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
853         content_debug("Time : %ld\n", time);
854
855         /* Third, Get item list of a folder */
856         GList *item_list = NULL;
857
858         for (i = 0; i < g_list_length(folder_list); i++) {
859                 unsigned int j = 0;
860                 char *folder_id = NULL;
861                 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
862
863                 get_folder_meta(folder_handle, &folder_id);
864
865                 ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
866                 SAFE_FREE(folder_id);
867
868                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
869                         content_error("media_folder_foreach_media_from_db failed: %d", ret);
870                         return -1;
871                 } else {
872                         content_error("media_folder_foreach_media_from_db success!");
873
874                         for (j = 0; j < g_list_length(item_list); j++) {
875                                 media_handle = (media_info_h)g_list_nth_data(item_list, j);
876                                 get_media_meta(media_handle);
877                         }
878                 }
879         }
880
881         /* Get tag list */
882         media_tag_h tag_handle = NULL;
883         GList *tag_list = NULL;
884         GList *media_list_in_tag = NULL;
885         int tag_id = 0;
886
887         ret = media_tag_foreach_tag_from_db(filter, gallery_tag_item_cb, &tag_list);
888
889         if (ret != MEDIA_CONTENT_ERROR_NONE) {
890                 content_error("media_tag_foreach_tag_from_db failed: %d", ret);
891                 return -1;
892         } else {
893                 content_error("media_tag_foreach_tag_from_db success");
894                 for (i = 0; i < g_list_length(tag_list); i++) {
895                         tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
896                         get_tag_meta(tag_handle);
897
898                         ret = media_tag_get_tag_id(tag_handle, &tag_id);
899                         if (ret != MEDIA_CONTENT_ERROR_NONE) {
900                                 ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag);
901                                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
902                                         content_error("media_tag_foreach_media_from_db failed: %d", ret);
903                                         return -1;
904                                 } else {
905                                         content_error("media_tag_foreach_media_from_db success");
906                                         unsigned int j = 0;
907                                         media_info_h tag_media_handle;
908
909                                         for (j = 0; j < g_list_length(media_list_in_tag); j++) {
910                                                 tag_media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, j);
911                                                 get_media_meta(tag_media_handle);
912                                         }
913                                 }
914                         }
915                 }
916         }
917
918         /* Remove folder list */
919         if (folder_list) {
920                 for (i = 0; i < g_list_length(folder_list); i++) {
921                         folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
922                         media_folder_destroy(folder_handle);
923                 }
924
925                 g_list_free(folder_list);
926         }
927
928         /* Remove all items list */
929         if (all_item_list) {
930                 for (i = 0; i < g_list_length(all_item_list); i++) {
931                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
932                         ret = media_info_destroy(media_handle);
933                         if (ret != MEDIA_CONTENT_ERROR_NONE)
934                                 content_error("media_info_destroy failed: %d", ret);
935                 }
936
937                 g_list_free(all_item_list);
938         }
939
940         /* Remove items list */
941         if (item_list) {
942                 for (i = 0; i < g_list_length(item_list); i++) {
943                         media_handle = (media_info_h)g_list_nth_data(item_list, i);
944                         ret = media_info_destroy(media_handle);
945                         if (ret != MEDIA_CONTENT_ERROR_NONE)
946                                 content_error("media_info_destroy failed: %d", ret);
947                 }
948
949                 g_list_free(item_list);
950         }
951
952         /* Remove tag list */
953         if (tag_list) {
954                 for (i = 0; i < g_list_length(tag_list); i++) {
955                         tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
956                         ret = media_tag_destroy(tag_handle);
957                         if (ret != MEDIA_CONTENT_ERROR_NONE)
958                                 content_error("error media_tag_destroy : [%d]", ret);
959                 }
960
961                 g_list_free(tag_list);
962         }
963
964         /* Remove media list in a tag */
965         if (media_list_in_tag) {
966                 for (i = 0; i < g_list_length(media_list_in_tag); i++) {
967                         media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, i);
968                         ret = media_info_destroy(media_handle);
969                         if (ret != MEDIA_CONTENT_ERROR_NONE)
970                                 content_error("media_info_destroy failed: %d", ret);
971                 }
972
973                 g_list_free(media_list_in_tag);
974         }
975
976         return MEDIA_CONTENT_ERROR_NONE;
977 }
978
979 /*Get All Music file. sort by Title and not case sensitive*/
980 int test_get_all_music_files(void)
981 {
982         int ret = MEDIA_CONTENT_ERROR_NONE;
983         int media_count = 0;
984         filter_h filter;
985
986         /*Set Filter*/
987         const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
988
989         ret = media_filter_create(&filter);
990         if (ret != MEDIA_CONTENT_ERROR_NONE) {
991                 content_error("Fail to create filter");
992                 return ret;
993         }
994         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED);
995         if (ret != MEDIA_CONTENT_ERROR_NONE) {
996                 media_filter_destroy(filter);
997                 content_error("Fail to set condition");
998                 return ret;
999         }
1000         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED);
1001         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1002                 media_filter_destroy(filter);
1003                 content_error("Fail to set order");
1004                 return ret;
1005         }
1006
1007         /*Get Media Count*/
1008         ret = media_info_get_media_count_from_db(filter, &media_count);
1009         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1010                 media_filter_destroy(filter);
1011                 content_error("Fail to get media count");
1012                 return ret;
1013         }
1014
1015         content_debug("media_count : [%d]", media_count);
1016
1017         ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
1018         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1019                 media_filter_destroy(filter);
1020                 content_error("Fail to get media");
1021                 return ret;
1022         }
1023
1024         ret = media_filter_destroy(filter);
1025
1026         return ret;
1027 }
1028
1029 int test_media_info_operation(void)
1030 {
1031         int ret = MEDIA_CONTENT_ERROR_NONE;
1032         int media_count = 0;
1033
1034         content_debug("\n============Media info Test============\n\n");
1035
1036         test_filter_create();
1037
1038         ret = media_info_get_media_count_from_db(g_filter, &media_count);
1039         if (ret != MEDIA_CONTENT_ERROR_NONE)
1040                 content_error("media_info_get_media_count_from_db failed: %d", ret);
1041         else
1042                 content_debug("media_count : [%d]", media_count);
1043
1044         ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
1045         if (ret == MEDIA_CONTENT_ERROR_NONE)
1046                 content_debug("media_info_foreach_media_from_db is success");
1047         else
1048                 content_error("media_info_foreach_media_from_db is failed");
1049
1050         test_filter_destroy();
1051
1052         return ret;
1053 }
1054
1055 int test_media_info_operation_2(void)
1056 {
1057         int ret = MEDIA_CONTENT_ERROR_NONE;
1058         int bookmark_count = 0;
1059
1060         content_debug("\n============Media info Test 2============\n\n");
1061
1062         test_filter_create();
1063
1064 #if 0
1065         /* Bookmark */
1066         char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1067         media_bookmark_insert_to_db(test_video_id, 100, thumbnail_path1);
1068         media_bookmark_insert_to_db(test_video_id, 200, thumbnail_path1);
1069
1070         media_info_get_bookmark_count_from_db(test_video_id, g_filter_g, &bookmark_count);
1071
1072         content_debug("bookmark_count : [%d]", bookmark_count);
1073
1074         ret = media_info_foreach_bookmark_from_db(test_video_id, g_filter_g, bookmarks_cb, NULL);
1075 #endif
1076
1077         /* Tag */
1078         ret = media_info_get_tag_count_from_db(test_audio_id, g_filter_g, &bookmark_count);
1079         if (ret != MEDIA_CONTENT_ERROR_NONE)
1080                 content_error("media_info_get_tag_count_from_db failed: %d", ret);
1081         else
1082                 content_debug("tag_count : [%d]", bookmark_count);
1083
1084         ret = media_info_foreach_tag_from_db(test_audio_id, g_filter_g, tag_list_cb, NULL);
1085         if (ret != MEDIA_CONTENT_ERROR_NONE)
1086                 content_error("media_info_foreach_tag_from_db failed: %d", ret);
1087
1088         test_filter_destroy();
1089
1090         return ret;
1091 }
1092
1093 int test_folder_operation(void)
1094 {
1095         int ret = MEDIA_CONTENT_ERROR_NONE;
1096         filter_h filter = NULL;
1097         media_folder_h folder = NULL;
1098         char *folder_id = NULL;
1099         int count = 0;
1100
1101         content_debug("\n============Folder Test============\n\n");
1102
1103         test_filter_create();
1104
1105         ret = media_filter_create(&filter);
1106         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1107                 content_error("[ERROR] media_folder_filter_create is failed");
1108                 return ret;
1109         }
1110
1111         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*/
1112         media_filter_set_offset(filter, 0, 5);
1113         media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1114
1115         ret = media_folder_get_folder_count_from_db(filter, &count);
1116         content_debug("Folder count : [%d]", count);
1117
1118         ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
1119
1120         filter_h m_filter = NULL;
1121
1122         ret = media_filter_create(&m_filter);
1123         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1124                 test_filter_destroy();
1125                 media_filter_destroy(filter);
1126                 content_error("[ERROR] media_info_filter_create is failed");
1127                 return ret;
1128         }
1129
1130         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*/
1131         media_filter_set_offset(m_filter, 0, 5);
1132         media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1133
1134         ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
1135         if (ret != MEDIA_CONTENT_ERROR_NONE)
1136                 content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret);
1137
1138         media_filter_destroy(filter);
1139         media_filter_destroy(m_filter);
1140
1141         test_filter_destroy();
1142
1143         /* fix prevent: Resource Leak */
1144         SAFE_FREE(folder_id);
1145
1146         return ret;
1147 }
1148
1149 int test_playlist_operation(void)
1150 {
1151         int ret = MEDIA_CONTENT_ERROR_NONE;
1152         media_playlist_h playlist_1 = NULL;
1153         media_playlist_h playlist_2 = NULL;
1154         media_playlist_h playlist_3 = NULL;
1155         media_playlist_h playlist_4 = NULL;
1156         int playlist_id_1 = 0;
1157         int playlist_id_2 = 0;
1158         int playlist_id_3 = 0;
1159         const char *playlist_name_1 = "myPlaylist_1";
1160         const char *playlist_name_2 = "myPlaylist_2";
1161         const char *playlist_name_3 = "myPlaylist_3";
1162         int playlist_count = 0;
1163         int media_count = 0;
1164         int order_1 = 0;
1165         int order_2 = 0;
1166         int order_3 = 0;
1167         int order_4 = 0;
1168         int order_5 = 0;
1169         filter_h filter = NULL;
1170         filter_h m_filter = NULL;
1171
1172         content_debug("\n============Playlist Test============\n\n");
1173
1174         /* Filter for playlist */
1175
1176         const char *condition = "(MEDIA_TYPE=1 or MEDIA_TYPE=3)";       /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1177
1178         ret = media_filter_create(&filter);
1179         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
1180         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_NAME, MEDIA_CONTENT_COLLATE_NOCASE);
1181
1182         /* Create Playlist */
1183         media_playlist_insert_to_db(playlist_name_1, &playlist_1);
1184         media_playlist_insert_to_db(playlist_name_2, &playlist_2);
1185         media_playlist_insert_to_db(playlist_name_3, &playlist_3);
1186
1187         if (playlist_1 != NULL) {
1188                 /* Add media to Playlist */
1189                 media_playlist_add_media(playlist_1, test_audio_id);
1190                 media_playlist_add_media(playlist_1, test_audio_id);
1191                 media_playlist_add_media(playlist_1, test_video_id);
1192
1193                 #if 0
1194                 char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg"));
1195                 media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1196                 #endif
1197
1198                 media_playlist_update_to_db(playlist_1);
1199         }
1200
1201         if (playlist_2 != NULL) {
1202                 media_playlist_add_media(playlist_2, test_audio_id);
1203                 media_playlist_add_media(playlist_2, test_audio_id);
1204                 media_playlist_update_to_db(playlist_2);
1205         }
1206
1207         /* Get Playlist Count*/
1208         ret = media_playlist_get_playlist_count_from_db(filter, &playlist_count);
1209         if (ret == 0)
1210                 content_debug("playlist_count [%d]", playlist_count);
1211
1212         /* Get Playlist*/
1213         GList *playlist_id_list = NULL;
1214         media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, &playlist_id_list);
1215         /* 64bit build issue */
1216 #if 0
1217         /* Get Playlist id*/
1218         playlist_id_1 = (int)g_list_nth_data(playlist_id_list, 0);
1219         playlist_id_2 = (int)g_list_nth_data(playlist_id_list, 1);
1220         playlist_id_3 = (int)g_list_nth_data(playlist_id_list, 2);
1221 #endif
1222         content_debug("playlist_id_1 [%d]", playlist_id_1);
1223         content_debug("playlist_id_2 [%d]", playlist_id_2);
1224         content_debug("playlist_id_3 [%d]", playlist_id_3);
1225
1226         /* Export and import playlist */
1227         media_playlist_export_to_file(playlist_3, tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"));
1228         media_playlist_import_from_file(tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"), "playlist_4", &playlist_4);
1229
1230         /* Filter for media*/
1231         ret = media_filter_create(&m_filter);
1232
1233         ret = media_filter_set_condition(m_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1234
1235         ret = media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_MEMBER_ORDER, MEDIA_CONTENT_COLLATE_DEFAULT);
1236
1237         /* Get media count */
1238         media_playlist_get_media_count_from_db(playlist_id_1, m_filter, &media_count);
1239         content_debug("playlist_1_media_count [%d]", media_count);
1240
1241         media_playlist_get_media_count_from_db(playlist_id_2, m_filter, &media_count);
1242         content_debug("playlist_2_media_count [%d]", media_count);
1243
1244         media_playlist_get_media_count_from_db(playlist_id_3, m_filter, &media_count);
1245         content_debug("playlist_3_media_count [%d]", media_count);
1246
1247         /* Get media of playlist */
1248         GList *playlist_member_id_list = NULL;
1249         GList *playlist_member_id_list_1 = NULL;
1250
1251         media_playlist_foreach_media_from_db(playlist_id_1, m_filter, playlist_item_cb, &playlist_member_id_list);
1252         media_playlist_foreach_media_from_db(playlist_id_2, m_filter, playlist_item_cb, &playlist_member_id_list_1);
1253
1254         int playlist_member_id_1_1 = 0;
1255         int playlist_member_id_1_2 = 0;
1256         int playlist_member_id_1_3 = 0;
1257         int playlist_member_id_2_1 = 0;
1258         int playlist_member_id_2_2 = 0;
1259         /* 64bit build issue */
1260 #if 0
1261         playlist_member_id_1_1 = (int)g_list_nth_data(playlist_member_id_list, 0);
1262         playlist_member_id_1_2 = (int)g_list_nth_data(playlist_member_id_list, 1);
1263         playlist_member_id_1_3 = (int)g_list_nth_data(playlist_member_id_list, 2);
1264         playlist_member_id_2_1 = (int)g_list_nth_data(playlist_member_id_list_1, 0);
1265         playlist_member_id_2_2 = (int)g_list_nth_data(playlist_member_id_list_1, 1);
1266 #endif
1267         content_debug("playlist_member_id_1_1 [%d]", playlist_member_id_1_1);
1268         content_debug("playlist_member_id_1_2 [%d]", playlist_member_id_1_2);
1269         content_debug("playlist_member_id_1_3 [%d]", playlist_member_id_1_3);
1270         content_debug("playlist_member_id_2_1 [%d]", playlist_member_id_2_1);
1271         content_debug("playlist_member_id_2_2 [%d]", playlist_member_id_2_2);
1272
1273         media_playlist_get_play_order(playlist_1, playlist_member_id_1_1, &order_1);
1274         media_playlist_get_play_order(playlist_1, playlist_member_id_1_2, &order_2);
1275         media_playlist_get_play_order(playlist_1, playlist_member_id_1_3, &order_3);
1276         media_playlist_get_play_order(playlist_2, playlist_member_id_2_1, &order_4);
1277         media_playlist_get_play_order(playlist_2, playlist_member_id_2_2, &order_5);
1278         content_debug("order_1 [%d] order_2 [%d] order_3 [%d] order_4 [%d] order_5 [%d]", order_1, order_2, order_3, order_4, order_5);
1279
1280         /* Update Playlist */
1281         media_playlist_remove_media(playlist_2, playlist_member_id_2_1);
1282         media_playlist_add_media(playlist_2, test_video_id);
1283         media_playlist_set_name(playlist_2, "test_playlist");
1284         media_playlist_set_play_order(playlist_2, playlist_member_id_2_2, order_5+100);
1285         media_playlist_update_to_db(playlist_2);
1286
1287         /* Get Updated Playlist*/
1288         media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, NULL);
1289
1290         /* deletes the playlist */
1291 #if 0
1292         media_playlist_delete_from_db(playlist_id_1);
1293         media_playlist_delete_from_db(playlist_id_2);
1294 #endif
1295
1296         if (playlist_1 != NULL)
1297                 media_playlist_destroy(playlist_1);
1298         if (playlist_2 != NULL)
1299                 media_playlist_destroy(playlist_2);
1300         if (playlist_3 != NULL)
1301                 media_playlist_destroy(playlist_3);
1302         if (playlist_4 != NULL)
1303                 media_playlist_destroy(playlist_4);
1304
1305         g_list_free(playlist_id_list);
1306         g_list_free(playlist_member_id_list);
1307         g_list_free(playlist_member_id_list_1);
1308
1309         if (filter != NULL)
1310                 ret = media_filter_destroy(filter);
1311         if (m_filter != NULL)
1312                 ret = media_filter_destroy(m_filter);
1313
1314         return ret;
1315 }
1316
1317 int test_playlist_operation_v2(void)
1318 {
1319         int ret = MEDIA_CONTENT_ERROR_NONE;
1320         media_playlist_h playlist_1 = NULL;
1321         const char *playlist_name_1 = "myPlaylist_1";
1322         const char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1323         int playlist_id = 0;
1324
1325         content_debug("\n============Playlist Test V2============\n\n");
1326
1327         ret = media_playlist_create(&playlist_1);
1328         if (ret != MEDIA_CONTENT_ERROR_NONE)
1329                 content_error("error media_playlist_create : [%d]", ret);
1330
1331         ret = media_playlist_set_name(playlist_1, playlist_name_1);
1332         if (ret != MEDIA_CONTENT_ERROR_NONE)
1333                 content_error("error media_playlist_set_name : [%d]", ret);
1334
1335         ret = media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1336         if (ret != MEDIA_CONTENT_ERROR_NONE)
1337                 content_error("error media_playlist_set_thumbnail_path : [%d]", ret);
1338
1339         ret = media_playlist_insert_to_db_v2(playlist_1);
1340         if (ret != MEDIA_CONTENT_ERROR_NONE)
1341                 content_error("error media_playlist_insert_to_db_v2 : [%d]", ret);
1342
1343         ret = media_playlist_set_name(playlist_1, "myPlaylist_3");
1344         if (ret != MEDIA_CONTENT_ERROR_NONE)
1345                 content_error("error media_playlist_set_name : [%d]", ret);
1346
1347         ret = media_playlist_get_playlist_id(playlist_1, &playlist_id);
1348         if (ret != MEDIA_CONTENT_ERROR_NONE)
1349                 content_error("error media_playlist_get_playlist_id : [%d]", ret);
1350
1351         ret = media_playlist_update_to_db_v2(playlist_id, playlist_1);
1352         if (ret != MEDIA_CONTENT_ERROR_NONE)
1353                 content_error("error media_playlist_update_to_db_v2 : [%d]", ret);
1354
1355         ret = media_playlist_destroy(playlist_1);
1356         if (ret != MEDIA_CONTENT_ERROR_NONE)
1357                 content_error("error media_playlist_destroy : [%d]", ret);
1358
1359         return ret;
1360 }
1361
1362 int test_tag_operation(void)
1363 {
1364         int ret = MEDIA_CONTENT_ERROR_NONE;
1365         media_tag_h tag_1;
1366         media_tag_h tag_2;
1367         media_tag_h tag_3;
1368         int tag_id_1 = 0;
1369         int tag_id_2 = 0;
1370         int tag_id_3 = 0;
1371         const char *tag_name_1 = "myTag_1";
1372         const char *tag_name_2 = "myTag_2";
1373         const char *tag_name_3 = "myTag_3";
1374         int tag_count = 0;
1375         int media_count = 0;
1376         filter_h filter;
1377
1378         content_debug("\n============Tag Test============\n\n");
1379
1380         const char *g_condition = "TAG_NAME like \"%%my%%\"";
1381
1382         ret = media_filter_create(&filter);
1383
1384         ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1385
1386         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
1387
1388         /* Create Tag */
1389         ret = media_tag_insert_to_db(tag_name_1, &tag_1);
1390         if (ret != MEDIA_CONTENT_ERROR_NONE)
1391                 content_error("error media_tag_insert_to_db : [%d]", ret);
1392         ret = media_tag_insert_to_db(tag_name_2, &tag_2);
1393         if (ret != MEDIA_CONTENT_ERROR_NONE)
1394                 content_error("error media_tag_insert_to_db : [%d]", ret);
1395         ret = media_tag_insert_to_db(tag_name_3, &tag_3);
1396         if (ret != MEDIA_CONTENT_ERROR_NONE)
1397                 content_error("error media_tag_insert_to_db : [%d]", ret);
1398
1399         /* Add media to Tag */
1400         ret = media_tag_add_media(tag_1, test_audio_id);
1401         if (ret != MEDIA_CONTENT_ERROR_NONE)
1402                 content_error("error media_tag_add_media : [%d]", ret);
1403         ret = media_tag_add_media(tag_1, test_video_id);
1404         if (ret != MEDIA_CONTENT_ERROR_NONE)
1405                 content_error("error media_tag_add_media : [%d]", ret);
1406         ret = media_tag_update_to_db(tag_1);
1407         if (ret != MEDIA_CONTENT_ERROR_NONE)
1408                 content_error("error media_tag_update_to_db : [%d]", ret);
1409
1410         ret = media_tag_add_media(tag_2, test_audio_id);
1411         if (ret != MEDIA_CONTENT_ERROR_NONE)
1412                 content_error("error media_tag_add_media : [%d]", ret);
1413         ret = media_tag_update_to_db(tag_2);
1414         if (ret != MEDIA_CONTENT_ERROR_NONE)
1415                 content_error("error media_tag_update_to_db : [%d]", ret);
1416
1417         /* Get Tag Count*/
1418         ret = media_tag_get_tag_count_from_db(filter, &tag_count);
1419         if (ret != MEDIA_CONTENT_ERROR_NONE)
1420                 content_error("error media_tag_get_tag_count_from_db : [%d]", ret);
1421         else
1422                 content_debug("tag_count [%d]", tag_count);
1423
1424         /* Get Tag*/
1425         ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1426         if (ret != MEDIA_CONTENT_ERROR_NONE)
1427                 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1428
1429         /* Get Tag id*/
1430         ret = media_tag_get_tag_id(tag_1, &tag_id_1);
1431         if (ret != MEDIA_CONTENT_ERROR_NONE)
1432                 content_error("error media_tag_get_tag_id : [%d]", ret);
1433         else
1434                 content_debug("tag_id_1 [%d]", tag_id_1);
1435
1436         ret = media_tag_get_tag_id(tag_2, &tag_id_2);
1437         if (ret != MEDIA_CONTENT_ERROR_NONE)
1438                 content_error("error media_tag_get_tag_id : [%d]", ret);
1439         else
1440                 content_debug("tag_id_2 [%d]", tag_id_2);
1441
1442         ret = media_tag_get_tag_id(tag_3, &tag_id_3);
1443         if (ret != MEDIA_CONTENT_ERROR_NONE)
1444                 content_error("error media_tag_get_tag_id : [%d]", ret);
1445         else
1446                 content_debug("tag_id_3 [%d]", tag_id_3);
1447
1448         /* Get media count */
1449         ret = media_tag_get_media_count_from_db(tag_id_1, NULL, &media_count);
1450         if (ret != MEDIA_CONTENT_ERROR_NONE)
1451                 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1452         else
1453                 content_debug("tag_1_media_count [%d]", media_count);
1454
1455         ret = media_tag_get_media_count_from_db(tag_id_2, NULL, &media_count);
1456         if (ret != MEDIA_CONTENT_ERROR_NONE)
1457                 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1458         else
1459                 content_debug("tag_2_media_count [%d]", media_count);
1460
1461         /* Get media of Tag */
1462         ret = media_tag_foreach_media_from_db(tag_id_1, NULL, media_item_cb, NULL);
1463         if (ret != MEDIA_CONTENT_ERROR_NONE)
1464                 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1465
1466         ret = media_tag_foreach_media_from_db(tag_id_2, NULL, media_item_cb, NULL);
1467         if (ret != MEDIA_CONTENT_ERROR_NONE)
1468                 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1469
1470         /* Update Tag */
1471         ret = media_tag_add_media(tag_2, test_video_id);
1472         if (ret != MEDIA_CONTENT_ERROR_NONE)
1473                 content_error("error media_tag_add_media : [%d]", ret);
1474         ret = media_tag_set_name(tag_2, "test_tag");
1475         if (ret != MEDIA_CONTENT_ERROR_NONE)
1476                 content_error("error media_tag_set_name : [%d]", ret);
1477         ret = media_tag_update_to_db(tag_2);
1478         if (ret != MEDIA_CONTENT_ERROR_NONE)
1479                 content_error("error media_tag_update_to_db : [%d]", ret);
1480
1481         /* Get Updated Tag*/
1482         ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1483         if (ret != MEDIA_CONTENT_ERROR_NONE)
1484                 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1485
1486         /* deletes the tag */
1487         ret = media_tag_delete_from_db(tag_id_1);
1488         if (ret != MEDIA_CONTENT_ERROR_NONE)
1489                 content_error("error media_tag_delete_from_db : [%d]", ret);
1490         ret = media_tag_delete_from_db(tag_id_2);
1491         if (ret != MEDIA_CONTENT_ERROR_NONE)
1492                 content_error("error media_tag_delete_from_db : [%d]", ret);
1493
1494         ret = media_tag_destroy(tag_1);
1495         if (ret != MEDIA_CONTENT_ERROR_NONE)
1496                 content_error("error media_tag_destroy : [%d]", ret);
1497         ret = media_tag_destroy(tag_2);
1498         if (ret != MEDIA_CONTENT_ERROR_NONE)
1499                 content_error("error media_tag_destroy : [%d]", ret);
1500         ret = media_tag_destroy(tag_3);
1501         if (ret != MEDIA_CONTENT_ERROR_NONE)
1502                 content_error("error media_tag_destroy : [%d]", ret);
1503         ret = media_filter_destroy(filter);
1504         if (ret != MEDIA_CONTENT_ERROR_NONE)
1505                 content_error("error media_filter_destroy : [%d]", ret);
1506
1507         return ret;
1508 }
1509
1510 int test_tag_operation_v2(void)
1511 {
1512         int ret = MEDIA_CONTENT_ERROR_NONE;
1513         media_tag_h tag_1;
1514         const char *tag_name_1 = "myTag_1";
1515         int tag_id = -1;
1516
1517         content_debug("\n============Tag Test V2============\n\n");
1518
1519         /* Create Tag */
1520         ret = media_tag_create(&tag_1);
1521         if (ret != MEDIA_CONTENT_ERROR_NONE)
1522                 content_error("error media_tag_create : [%d]", ret);
1523
1524         ret = media_tag_set_name(tag_1, tag_name_1);
1525         if (ret != MEDIA_CONTENT_ERROR_NONE)
1526                 content_error("error media_tag_set_name : [%d]", ret);
1527
1528         /* Add media to Tag */
1529         ret = media_tag_add_media(tag_1, test_audio_id);
1530         if (ret != MEDIA_CONTENT_ERROR_NONE)
1531                 content_error("error media_tag_add_media : [%d]", ret);
1532
1533         ret = media_tag_add_media(tag_1, test_video_id);
1534         if (ret != MEDIA_CONTENT_ERROR_NONE)
1535                 content_error("error media_tag_add_media : [%d]", ret);
1536
1537         ret = media_tag_insert_to_db_v2(tag_1);
1538         if (ret != MEDIA_CONTENT_ERROR_NONE)
1539                 content_error("error media_tag_insert_to_db_v2 : [%d]", ret);
1540
1541 #if 1
1542         ret = media_tag_get_tag_id(tag_1, &tag_id);
1543         if (ret != MEDIA_CONTENT_ERROR_NONE)
1544                 content_error("error media_tag_get_tag_id : [%d]", ret);
1545
1546         ret = media_tag_remove_media(tag_1, test_video_id);
1547         if (ret != MEDIA_CONTENT_ERROR_NONE)
1548                 content_error("error media_tag_add_media : [%d]", ret);
1549
1550         ret = media_tag_update_to_db_v2(tag_id, tag_1);
1551         if (ret != MEDIA_CONTENT_ERROR_NONE)
1552                 content_error("error media_tag_update_to_db_v2 : [%d]", ret);
1553 #endif
1554
1555         ret = media_tag_destroy(tag_1);
1556         if (ret != MEDIA_CONTENT_ERROR_NONE)
1557                 content_error("error media_tag_destroy : [%d]", ret);
1558
1559         return ret;
1560 }
1561
1562 static void __bookmark_handle_free(gpointer data)
1563 {
1564         media_bookmark_h handle = (media_bookmark_h) data;
1565         media_bookmark_destroy(handle);
1566 }
1567
1568 int test_bookmark_operation(void)
1569 {
1570         /* bookmark is only supported for video information. */
1571         int ret = MEDIA_CONTENT_ERROR_NONE;
1572         int bookmark_count = 0;
1573         filter_h filter;
1574         GList *all_item_list = NULL;
1575         int idx = 0;
1576
1577         content_debug("\n============Bookmark Test============\n\n");
1578
1579         const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
1580
1581         ret = media_filter_create(&filter);
1582         if (ret != MEDIA_CONTENT_ERROR_NONE)
1583                 content_error("error media_filter_create : [%d]", ret);
1584
1585         ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1586         if (ret != MEDIA_CONTENT_ERROR_NONE)
1587                 content_error("error media_filter_set_condition : [%d]", ret);
1588
1589         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, BOOKMARK_MARKED_TIME, MEDIA_CONTENT_COLLATE_DEFAULT);
1590         if (ret != MEDIA_CONTENT_ERROR_NONE)
1591                 content_error("error media_filter_set_order : [%d]", ret);
1592
1593         /* insert bookmark to video */
1594         const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1595         ret = media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1);
1596         if (ret != MEDIA_CONTENT_ERROR_NONE)
1597                 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1598
1599         ret = media_bookmark_insert_to_db(test_video_id, 600, thumbnail_path1);
1600         if (ret != MEDIA_CONTENT_ERROR_NONE)
1601                 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1602
1603         ret = media_bookmark_get_bookmark_count_from_db(filter, &bookmark_count);
1604         if (ret != MEDIA_CONTENT_ERROR_NONE)
1605                 content_error("error media_bookmark_get_bookmark_count_from_db : [%d]", ret);
1606         else
1607                 content_debug("bookmark_count = [%d]", bookmark_count);
1608
1609         ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, &all_item_list);
1610         if (ret != MEDIA_CONTENT_ERROR_NONE)
1611                 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1612
1613         for (idx = 0; idx < g_list_length(all_item_list); idx++) {
1614                 media_bookmark_h bookmark_handle;
1615                 bookmark_handle = (media_bookmark_h)g_list_nth_data(all_item_list, idx);
1616
1617                 ret = media_bookmark_set_name(bookmark_handle, "test 1");
1618                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1619                         content_error("error media_bookmark_set_name : [%d]", ret);
1620
1621                 ret = media_bookmark_update_to_db(bookmark_handle);
1622                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1623                         content_error("error media_bookmark_update_to_db : [%d]", ret);
1624         }
1625
1626         if (all_item_list)
1627                 g_list_free_full(all_item_list, __bookmark_handle_free);
1628
1629         ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, NULL);
1630         if (ret != MEDIA_CONTENT_ERROR_NONE)
1631                 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1632
1633         ret = media_filter_destroy(filter);
1634         if (ret != MEDIA_CONTENT_ERROR_NONE)
1635                 content_error("error media_filter_destroy : [%d]", ret);
1636
1637         return ret;
1638 }
1639
1640 int test_bookmark_operation_v2(void)
1641 {
1642         content_debug("\n============Bookmark Test V2============\n\n");
1643
1644         int ret = MEDIA_CONTENT_ERROR_NONE;
1645         media_bookmark_h bookmark = NULL;
1646         const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1647
1648         ret = media_bookmark_create(test_video_id, 400, &bookmark);
1649         if (ret != MEDIA_CONTENT_ERROR_NONE)
1650                 content_error("error media_bookmark_create : [%d]", ret);
1651
1652         ret = media_bookmark_set_name(bookmark, "test bookmark");
1653         if (ret != MEDIA_CONTENT_ERROR_NONE)
1654                 content_error("error media_bookmark_set_name : [%d]", ret);
1655
1656         ret = media_bookmark_set_thumbnail_path(bookmark, thumbnail_path1);
1657         if (ret != MEDIA_CONTENT_ERROR_NONE)
1658                 content_error("error media_bookmark_set_thumbnail_path : [%d]", ret);
1659
1660         ret = media_bookmark_insert_to_db_v2(bookmark);
1661         if (ret != MEDIA_CONTENT_ERROR_NONE)
1662                 content_error("error media_bookmark_insert_to_db_v2 : [%d]", ret);
1663
1664         ret = media_bookmark_set_name(bookmark, "test bookmark 2");
1665         if (ret != MEDIA_CONTENT_ERROR_NONE)
1666                 content_error("error media_bookmark_set_name : [%d]", ret);
1667
1668         ret = media_bookmark_update_to_db(bookmark);
1669         if (ret != MEDIA_CONTENT_ERROR_NONE)
1670                 content_error("error media_bookmark_update_to_db : [%d]", ret);
1671
1672         ret = media_bookmark_destroy(bookmark);
1673         if (ret != MEDIA_CONTENT_ERROR_NONE)
1674                 content_error("error media_bookmark_destroy : [%d]", ret);
1675
1676         return ret;
1677 }
1678
1679 int test_album_list(void)
1680 {
1681         content_debug("\n============Album Test============\n\n");
1682
1683         int ret = MEDIA_CONTENT_ERROR_NONE;
1684         int album_count = 0;
1685         filter_h filter;
1686
1687         /*Set Filter*/
1688         const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1689
1690         ret = media_filter_create(&filter);
1691         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1692                 content_error("Fail to create filter");
1693                 return ret;
1694         }
1695         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1696         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1697                 media_filter_destroy(filter);
1698                 content_error("Fail to set condition");
1699                 return ret;
1700         }
1701         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
1702         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1703                 media_filter_destroy(filter);
1704                 content_error("Fail to set order");
1705                 return ret;
1706         }
1707
1708         ret = media_album_get_album_count_from_db(filter, &album_count);
1709         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1710                 media_filter_destroy(filter);
1711                 return ret;
1712         } else {
1713                 content_debug("album_count [%d]", album_count);
1714         }
1715
1716         ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
1717         if (ret != MEDIA_CONTENT_ERROR_NONE)
1718                 content_error("error media_album_foreach_album_from_db : [%d]", ret);
1719
1720         ret = media_filter_destroy(filter);
1721         if (ret != MEDIA_CONTENT_ERROR_NONE)
1722                 content_error("error media_filter_destroy : [%d]", ret);
1723
1724         return ret;
1725 }
1726
1727 int test_group_operation(void)
1728 {
1729         content_debug("\n============Group Test============\n\n");
1730
1731         int ret = MEDIA_CONTENT_ERROR_NONE;
1732         int group_count = 0;
1733         int idx = 0;
1734
1735         ret = test_filter_create();
1736         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1737                 content_error("[error(0x%08x)", ret);
1738                 return ret;
1739         }
1740
1741         for (idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) {
1742                 ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
1743                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1744                         test_filter_destroy();
1745                         content_error("media_group_get_group_count_from_db fail. ret=[%d] idx=[%d]", ret, idx);
1746                         return ret;
1747                 } else {
1748                         content_debug("[%2d]group_count [%d]", idx, group_count);
1749                 }
1750
1751                 ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
1752                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1753                         content_error("media_group_foreach_group_from_db failed: %d", ret);
1754         }
1755         ret = test_filter_destroy();
1756
1757         return ret;
1758 }
1759
1760 int test_update_operation()
1761 {
1762         int ret = MEDIA_CONTENT_ERROR_NONE;
1763         unsigned int i = 0;
1764         media_info_h media_handle = NULL;
1765         GList *all_item_list = NULL;
1766
1767         /* Get all item list */
1768         ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
1769         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1770                 content_error("media_info_foreach_media_from_db failed: %d", ret);
1771                 return -1;
1772         } else {
1773                 content_debug("media_info_foreach_media_from_db success");
1774
1775                 for (i = 0; i < g_list_length(all_item_list); i++) {
1776                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
1777                         get_media_meta(media_handle);
1778                 }
1779         }
1780
1781         return MEDIA_CONTENT_ERROR_NONE;
1782 }
1783
1784 int test_insert(void)
1785 {
1786         int ret = MEDIA_CONTENT_ERROR_NONE;
1787         const char *path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1788 #if 0
1789         const char *path = tzplatform_mkpath(TZ_USER_DOCUMENTS, "other.txt"));
1790         char *path = NULL;
1791 #endif
1792         media_info_h media_item = NULL;
1793         content_debug("\n============DB Insert Test============\n\n");
1794
1795         ret = media_info_insert_to_db(path, &media_item);
1796
1797         if ((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) {
1798                 content_debug("Insertion is success");
1799         } else {
1800                 content_error("Insertion is failed");
1801                 ret = media_info_destroy(media_item);
1802                 return ret;
1803         }
1804
1805         char *media_id = NULL;
1806
1807         ret = media_info_get_media_id(media_item, &media_id);
1808         if (ret != MEDIA_CONTENT_ERROR_NONE)
1809                 content_error("media_info_get_media_id failed: %d", ret);
1810         else
1811                 content_debug("Media ID: %s", media_id);
1812
1813         SAFE_FREE(media_id);
1814
1815         ret = media_info_update_to_db(media_item);
1816         if (ret == MEDIA_CONTENT_ERROR_NONE)
1817                 content_debug("media_info_update_to_db is success");
1818         else
1819                 content_error("media_info_update_to_db is failed");
1820
1821         ret = media_info_destroy(media_item);
1822         if (ret != MEDIA_CONTENT_ERROR_NONE)
1823                 content_error("media_info_destroy failed: %d", ret);
1824
1825         return ret;
1826 }
1827
1828 int test_move(void)
1829 {
1830         int ret = MEDIA_CONTENT_ERROR_NONE;
1831         const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
1832         const char *dst_path = tzplatform_mkpath(TZ_USER_IMAGES, "XX/Default1.jpg");
1833         media_info_h move_media = NULL;
1834
1835         ret = media_info_get_media_from_db(move_media_id, &move_media);
1836         if (ret == MEDIA_CONTENT_ERROR_NONE)
1837                 content_debug("media_info_get_media_from_db success");
1838         else
1839                 content_error("media_info_get_media_from_db failed: %d", ret);
1840
1841         content_debug("\n============DB Move Test============\n\n");
1842
1843         if (move_media) {
1844                 ret = media_info_move_to_db(move_media, dst_path);
1845
1846                 if (ret == MEDIA_CONTENT_ERROR_NONE)
1847                         content_debug("Move is success");
1848                 else
1849                         content_error("Move is failed");
1850
1851                 ret = media_info_destroy(move_media);
1852         } else {
1853                 content_debug("There is no item : %s", move_media_id);
1854         }
1855
1856         return ret;
1857 }
1858
1859 int test_create_thumbnail(const char *path)
1860 {
1861         int ret = MEDIA_CONTENT_ERROR_NONE;
1862         media_info_h media;
1863         char *thumb_path = NULL;
1864
1865         ret = media_info_insert_to_db(path, &media);
1866         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_info_insert_to_db failed [%d]", ret);
1867
1868         ret = media_info_generate_thumbnail(media);
1869         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1870                 content_error("media_info_generate_thumbnail failed [%d]", ret);
1871                 goto FINALIZE;
1872         }
1873
1874         ret = media_info_get_thumbnail_path(media, &thumb_path);
1875         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1876                 content_error("media_info_get_thumbnail_path failed [%d]", ret);
1877                 goto FINALIZE;
1878         }
1879
1880         content_debug("Thumbnail Path [%s]", thumb_path);
1881         if (thumb_path)
1882                 free(thumb_path);
1883
1884 FINALIZE:
1885         media_info_destroy(media);
1886         return ret;
1887 }
1888
1889 bool face_cb(media_face_h face, void *user_data)
1890 {
1891         get_face_meta(face);
1892
1893         return false;
1894 }
1895
1896 void face_detection_complete_cb(media_content_error_e error, int count, void *user_data)
1897 {
1898         int ret = MEDIA_CONTENT_ERROR_NONE;
1899         g_cnt++;
1900
1901         content_debug("=================[%d][%d]", g_media_cnt, g_cnt);
1902         content_debug("error_code [%d]", error);
1903         content_debug("face_count [%d]", count);
1904         if (count == 0) {
1905                 content_debug("No faces are detected!");
1906         } else if (user_data != NULL) {
1907                 media_info_h media = (media_info_h)user_data;
1908                 char *media_id = NULL;
1909                 ret = media_info_get_media_id(media, &media_id);
1910                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1911                         content_error("media_info_get_media_id failed: %d", ret);
1912                 if (media_id != NULL) {
1913                         ret = media_info_foreach_face_from_db(media_id, NULL, face_cb, NULL);
1914                         SAFE_FREE(media_id);
1915                         if (ret != MEDIA_CONTENT_ERROR_NONE)
1916                                 content_error("media_info_foreach_face_from_db failed: %d", ret);
1917                 }
1918                 ret = media_info_destroy(media);
1919                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1920                         content_error("media_info_destroy failed: %d", ret);
1921         }
1922
1923         if (g_cnt == g_media_cnt)
1924                 g_main_loop_quit(g_loop);
1925
1926         return;
1927 }
1928
1929 bool start_face_detection_cb(media_info_h media, void *user_data)
1930 {
1931         char *media_id = NULL;
1932         media_info_h dst = NULL;
1933         int ret = MEDIA_CONTENT_ERROR_NONE;
1934
1935         if (media == NULL) {
1936                 content_debug("NO Item");
1937                 return true;
1938         }
1939
1940         ret = media_info_get_media_id(media, &media_id);
1941         if (ret != MEDIA_CONTENT_ERROR_NONE)
1942                 content_error("media_info_get_media_id failed: %d", ret);
1943         else
1944                 content_debug("media_id : [%s]", media_id);
1945
1946         ret = media_info_clone(&dst, media);
1947         if (ret != MEDIA_CONTENT_ERROR_NONE)
1948                 content_error("media_info_clone failed: %d", ret);
1949
1950         GList **list = (GList**)user_data;
1951         *list = g_list_append(*list, dst);
1952
1953         /* fix prevent: Resource leak */
1954         SAFE_FREE(media_id);
1955
1956         return true;
1957 }
1958
1959 bool cancel_face_detection_cb(media_info_h media, void *user_data)
1960 {
1961         int ret = MEDIA_CONTENT_ERROR_NONE;
1962
1963         char *media_id = NULL;
1964         media_info_h dst = NULL;
1965
1966         g_cnt++;
1967
1968         if (media == NULL) {
1969                 content_debug("NO Item");
1970                 return true;
1971         }
1972
1973         ret = media_info_get_media_id(media, &media_id);
1974         if (ret != MEDIA_CONTENT_ERROR_NONE)
1975                 content_error("media_info_get_media_id failed: %d", ret);
1976         else
1977                 content_debug("media_id : [%s]", media_id);
1978
1979         ret = media_info_clone(&dst, media);
1980         if (ret != MEDIA_CONTENT_ERROR_NONE)
1981                 content_error("media_info_clone failed: %d", ret);
1982
1983         ret = media_info_cancel_face_detection(dst);
1984         if (ret != MEDIA_CONTENT_ERROR_NONE)
1985                 content_error("media_info_cancel_face_detection failed: %d", ret);
1986
1987         ret = media_info_destroy(dst);
1988         if (ret != MEDIA_CONTENT_ERROR_NONE)
1989                         content_error("media_info_destroy failed: %d", ret);
1990
1991         if (g_cnt == g_media_cnt)
1992                 g_main_loop_quit(g_loop);
1993
1994         /* fix prevent: Resource leak */
1995         SAFE_FREE(media_id);
1996
1997         return true;
1998 }
1999
2000 gboolean face_detection_start(gpointer data)
2001 {
2002         int ret = MEDIA_CONTENT_ERROR_NONE;
2003         GList *all_item_list = NULL;
2004         int idx = 0;
2005
2006         ret = media_info_foreach_media_from_db(g_filter, start_face_detection_cb, &all_item_list);
2007
2008         if (ret == MEDIA_CONTENT_ERROR_NONE)
2009                 content_debug("media_info_foreach_media_from_db is success");
2010         else
2011                 content_error("media_info_foreach_media_from_db is failed");
2012
2013         for (idx = 0; idx < g_list_length(all_item_list); idx++) {
2014                 media_info_h media_handle = NULL;
2015
2016                 media_handle = (media_info_h)g_list_nth_data(all_item_list, idx);
2017
2018                 ret = media_info_start_face_detection(media_handle, face_detection_complete_cb, NULL);
2019                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2020                         content_error("media_info_start_face_detection failed: %d", ret);
2021
2022         }
2023
2024         return false;
2025 }
2026
2027 gboolean face_detection_cancel(gpointer data)
2028 {
2029         int ret = MEDIA_CONTENT_ERROR_NONE;
2030
2031         ret = media_info_foreach_media_from_db(g_filter, cancel_face_detection_cb, NULL);
2032
2033         if (ret == MEDIA_CONTENT_ERROR_NONE)
2034                 content_debug("media_info_foreach_media_from_db is success");
2035         else
2036                 content_error("media_info_foreach_media_from_db is failed");
2037
2038         return false;
2039 }
2040
2041 int test_start_face_detection(int cancel)
2042 {
2043         int ret = MEDIA_CONTENT_ERROR_NONE;
2044         GSource *source = NULL;
2045         GMainContext *context = NULL;
2046
2047         test_filter_create();
2048
2049         ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt);
2050         if (ret != MEDIA_CONTENT_ERROR_NONE)
2051                 content_error("media_info_get_media_count_from_db failed: %d", ret);
2052         else
2053                 content_debug("media_count : [%d]", g_media_cnt);
2054
2055         if (g_media_cnt == 0)
2056                 goto END;
2057
2058         g_loop = g_main_loop_new(NULL, FALSE);
2059         context = g_main_loop_get_context(g_loop);
2060         source = g_idle_source_new();
2061         g_source_set_callback(source, face_detection_start, NULL, NULL);
2062         g_source_attach(source, context);
2063
2064         /* Logic to cancel */
2065         if (cancel) {
2066                 GSource *cancel_src = NULL;
2067                 cancel_src = g_idle_source_new();
2068                 g_source_set_callback(cancel_src, face_detection_cancel, NULL, NULL);
2069                 g_source_attach(cancel_src, context);
2070         }
2071
2072         g_main_loop_run(g_loop);
2073         g_main_loop_unref(g_loop);
2074
2075 END:
2076         test_filter_destroy();
2077
2078         return ret;
2079 }
2080
2081 int test_ebook_text_finder(const char *keyword)
2082 {
2083         int ret = MEDIA_CONTENT_ERROR_NONE;
2084         char **book_path_list = NULL;
2085         unsigned int book_path_len = 0;
2086         unsigned int i = 0;
2087         media_info_h media = NULL;
2088         book_meta_h book = NULL;
2089         char *s_value = NULL;
2090         long long ms_time = 0;
2091         struct timeval start_time;
2092         struct timeval end_time;
2093
2094         gettimeofday(&start_time, NULL);
2095
2096         ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
2097         if (ret == MEDIA_CONTENT_ERROR_NONE)
2098                 content_debug("book_meta_get_path_with_keyword is success");
2099         else
2100                 content_error("book_meta_get_path_with_keyword is failed");
2101
2102         gettimeofday(&end_time, NULL);
2103
2104         for (i = 0; i < book_path_len; i++) {
2105                 ret = media_info_get_media_from_db_by_path(book_path_list[i], &media);
2106                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2107                         continue;
2108
2109                 content_debug("===============================");
2110                 content_debug("[%d] %s", i, book_path_list[i]);
2111                 content_debug("===============================");
2112                 media_info_get_title(media, &s_value);
2113                 content_debug("Title  : %s", s_value);
2114                 g_free(s_value);
2115                 s_value = NULL;
2116
2117                 ret = media_info_get_book(media, &book);
2118                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2119                         media_info_destroy(media);
2120                         continue;
2121                 }
2122
2123                 ret = book_meta_get_author(book, &s_value);
2124                 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
2125                         content_debug("Author : %s", s_value);
2126                         g_free(s_value);
2127                         s_value = NULL;
2128                 }
2129
2130                 ret = book_meta_get_date(book, &s_value);
2131                 if (ret == MEDIA_CONTENT_ERROR_NONE && s_value) {
2132                         content_debug("Date   : %s", s_value);
2133                         g_free(s_value);
2134                         s_value = NULL;
2135                 }
2136
2137                 content_debug("===============================");
2138                 ret = book_meta_destroy(book);
2139                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2140                         content_error("book_meta_destroy failed");
2141
2142                 ret = media_info_destroy(media);
2143                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2144                         content_error("media_info_destroy failed");
2145
2146                 g_free(book_path_list[i]);
2147         }
2148
2149         ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
2150         content_debug("Search Time [%lld]", ms_time);
2151
2152         g_free(book_path_list);
2153
2154         return ret;
2155 }
2156 int test_disconnect_database(void)
2157 {
2158         int ret = MEDIA_CONTENT_ERROR_NONE;
2159         content_debug("\n============DB Disconnection Test============\n\n");
2160
2161         ret = media_content_disconnect();
2162
2163         if (ret == MEDIA_CONTENT_ERROR_NONE)
2164                 content_debug("disconnection is success");
2165         else
2166                 content_error("disconnection is failed");
2167
2168         return ret;
2169 }
2170
2171 int test_request_update_db(void)
2172 {
2173         int ret = MEDIA_CONTENT_ERROR_NONE;
2174         media_info_h media = NULL;
2175         bool favorite = FALSE;
2176
2177         ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2178         if (ret != MEDIA_CONTENT_ERROR_NONE)
2179                 content_error("media_info_get_media_from_db failed: %d", ret);
2180
2181         ret = media_info_set_favorite(media, TRUE);
2182         if (ret != MEDIA_CONTENT_ERROR_NONE)
2183                 content_error("media_info_set_favorite failed: %d", ret);
2184
2185         ret = media_info_update_to_db(media);
2186         if (ret == MEDIA_CONTENT_ERROR_NONE)
2187                 content_debug("media_info_update_to_db is success");
2188         else
2189                 content_error("media_info_update_to_db is failed");
2190
2191         if (media != NULL)
2192                 media_info_destroy(media);
2193
2194         /*get the updated value*/
2195         ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2196         if (ret != MEDIA_CONTENT_ERROR_NONE)
2197                 content_error("media_info_get_media_from_db failed: %d", ret);
2198
2199         ret = media_info_get_favorite(media, &favorite);
2200         if (ret != MEDIA_CONTENT_ERROR_NONE)
2201                 content_error("media_info_get_favorite failed: %d", ret);
2202         else
2203                 content_debug("favorite [%d]", favorite);
2204
2205         ret = media_info_destroy(media);
2206
2207         return ret;
2208 }
2209
2210 static int g_total_photo_size = 0;
2211 static int g_total_video_size = 0;
2212 static int g_total_mp3_size = 0;
2213 static int g_total_voice_memo_size = 0;
2214
2215 bool dft_cb(media_info_h media, void *user_data)
2216 {
2217         unsigned long long file_size = 0;
2218         media_content_type_e media_type = -1;
2219         char *mime_type = NULL;
2220         int ret = MEDIA_CONTENT_ERROR_NONE;
2221
2222         if (media == NULL)
2223                 return true;
2224
2225         ret = media_info_get_media_type(media, &media_type);
2226         if (ret != MEDIA_CONTENT_ERROR_NONE)
2227                 content_error("media_info_get_media_type failed: %d", ret);
2228         ret = media_info_get_size(media, &file_size);
2229         if (ret != MEDIA_CONTENT_ERROR_NONE)
2230                 content_error("media_info_get_size failed: %d", ret);
2231         ret = media_info_get_mime_type(media, &mime_type);
2232         if (ret != MEDIA_CONTENT_ERROR_NONE)
2233                 content_error("media_info_get_mime_type failed: %d", ret);
2234
2235         if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
2236                 g_total_photo_size += file_size;
2237         else if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
2238                 g_total_video_size += file_size;
2239         else if (media_type == MEDIA_CONTENT_TYPE_SOUND)
2240                 g_total_voice_memo_size += file_size;
2241         else if (media_type == MEDIA_CONTENT_TYPE_MUSIC) {
2242                 if ((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
2243                         g_total_mp3_size += file_size;
2244                 else
2245                         g_total_voice_memo_size += file_size;
2246         } else
2247                 content_debug("invalid media_type");
2248
2249         SAFE_FREE(mime_type);
2250
2251         return true;
2252
2253 }
2254
2255 int DFT_test(void)
2256 {
2257         int ret = MEDIA_CONTENT_ERROR_NONE;
2258         content_debug("\n============DFT_test============\n\n");
2259
2260         filter_h filter = NULL;
2261         int media_cnt = 0;
2262
2263         /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
2264
2265         ret = media_filter_create(&filter);
2266
2267 /*Internal Memory*/
2268         content_debug("[Internal Memory]\n");
2269         /*1. Photo ============================================================*/
2270         ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2271
2272         /*Get Photo Count*/
2273         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2274         content_debug("Photo count = [%d]\n", media_cnt);
2275
2276         /*Get Photo Size*/
2277         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2278         content_debug("Photo size = [%d]\n", g_total_photo_size);
2279
2280         /*2. Video ============================================================*/
2281         ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2282
2283         /*Get Video Count*/
2284         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2285         content_debug("Video count = [%d]\n", media_cnt);
2286
2287         /*Get Video Size*/
2288         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2289         content_debug("Video size = [%d]\n", g_total_video_size);
2290
2291         /*3. MP3 ============================================================*/
2292         ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2293
2294         /*Get MP3 Count*/
2295         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2296         content_debug("MP3 count = [%d]\n", media_cnt);
2297
2298         /*Get MP3 Size*/
2299         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2300         content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2301
2302         /*4. Voice Memo ============================================================*/
2303         ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
2304
2305         /*Get Voice Memo Count*/
2306         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2307         content_debug("Voice Memo count = [%d]\n", media_cnt);
2308
2309         /*Get Voice Memo Size*/
2310         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2311         content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2312
2313         g_total_photo_size = 0;
2314         g_total_video_size = 0;
2315         g_total_mp3_size = 0;
2316         g_total_voice_memo_size = 0;
2317
2318 /*External Memory*/
2319         content_debug("\n[External Memory]\n");
2320         /*1. Photo ============================================================*/
2321         ret = media_filter_set_condition(filter, "MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2322
2323         /*Get Photo Count*/
2324         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2325         content_debug("Photo count = [%d]\n", media_cnt);
2326
2327         /*Get Photo Size*/
2328         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2329         content_debug("Photo size = [%d]\n", g_total_photo_size);
2330
2331         /*2. Video ============================================================*/
2332         ret = media_filter_set_condition(filter, "MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2333
2334         /*Get Video Count*/
2335         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2336         content_debug("Video count = [%d]\n", media_cnt);
2337
2338         /*Get Video Size*/
2339         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2340         content_debug("Video size = [%d]\n", g_total_video_size);
2341
2342         /*3. MP3 ============================================================*/
2343         ret = media_filter_set_condition(filter, "MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2344
2345         /*Get MP3 Count*/
2346         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2347         content_debug("MP3 count = [%d]\n", media_cnt);
2348
2349         /*Get MP3 Size*/
2350         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2351         content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2352
2353         /*4. Voice Memo ============================================================*/
2354         ret = media_filter_set_condition(filter, "(MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
2355
2356         /*Get Voice Memo Count*/
2357         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2358         content_debug("Voice Memo count = [%d]\n", media_cnt);
2359
2360         /*Get Voice Memo Size*/
2361         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2362         content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2363         ret = media_filter_destroy(filter);
2364
2365         return ret;
2366 }
2367
2368 void insert_batch_cb(media_content_error_e error, void * user_data)
2369 {
2370         content_debug("media_info_insert_batch_to_db completed!\n");
2371 }
2372
2373 int test_batch_operations()
2374 {
2375         int ret = -1;
2376         int i = 0;
2377         char *file_list[10];
2378
2379         for (i = 0; i < 10; i++) {
2380                 file_list[i] = g_strdup_printf("%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), i+1);
2381                 content_debug("File : %s\n", file_list[i]);
2382         }
2383
2384         ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL);
2385         if (ret != MEDIA_CONTENT_ERROR_NONE)
2386                 content_error("media_info_insert_batch_to_db failed : %d\n", ret);
2387
2388         for (i = 0; i < 10; i++)
2389                 g_free(file_list[i]);
2390
2391         return ret;
2392 }
2393
2394 void _scan_cb(media_content_error_e err, void *user_data)
2395 {
2396         content_debug("scan callback is called : %d\n", err);
2397         g_main_loop_quit(g_loop);
2398
2399         return;
2400 }
2401
2402 int test_scan_file()
2403 {
2404         int ret = -1;
2405
2406         const char *file_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2407         ret = media_content_scan_file(file_path);
2408         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2409                 content_error("Fail to media_content_scan_file : %d", ret);
2410                 return ret;
2411         }
2412
2413         return 0;
2414 }
2415
2416 gboolean test_scan_dir_start(gpointer data)
2417 {
2418         int ret = -1;
2419
2420         const char *dir_path = tzplatform_getenv(TZ_USER_CONTENT);
2421
2422         ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL);
2423
2424         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2425                 content_error("Fail to test_scan_dir_start : %d", ret);
2426                 return ret;
2427         }
2428
2429         return 0;
2430 }
2431
2432 gboolean cancel_scan_dir_start(gpointer data)
2433 {
2434         int ret = MEDIA_CONTENT_ERROR_NONE;
2435
2436         const char *dir_path = tzplatform_getenv(TZ_USER_IMAGES);
2437
2438         ret = media_content_cancel_scan_folder(dir_path);
2439
2440         if (ret == MEDIA_CONTENT_ERROR_NONE)
2441                 content_debug("media_content_cancel_scan_folder is success");
2442         else
2443                 content_error("media_content_cancel_scan_folder is failed");
2444
2445         return false;
2446 }
2447
2448 int test_scan_dir(int cancel)
2449 {
2450         GSource *source = NULL;
2451         GMainContext *context = NULL;
2452
2453         g_loop = g_main_loop_new(NULL, FALSE);
2454         context = g_main_loop_get_context(g_loop);
2455         source = g_idle_source_new();
2456         g_source_set_callback(source, test_scan_dir_start, NULL, NULL);
2457         g_source_attach(source, context);
2458
2459         if (cancel) {
2460                 GSource *cancel_src = NULL;
2461                 cancel_src = g_idle_source_new();
2462                 g_source_set_callback(cancel_src, cancel_scan_dir_start, NULL, NULL);
2463                 g_source_attach(cancel_src, context);
2464         }
2465
2466         g_main_loop_run(g_loop);
2467         g_main_loop_unref(g_loop);
2468
2469         return 0;
2470 }
2471
2472 void _noti_cb(media_content_error_e error,
2473                                 int pid,
2474                                 media_content_db_update_item_type_e update_item,
2475                                 media_content_db_update_type_e update_type,
2476                                 media_content_type_e media_type,
2477                                 char *uuid,
2478                                 char *path,
2479                                 char *mime_type,
2480                                 void *user_data)
2481 {
2482         if (error == 0)
2483                 content_debug("noti success! : %d\n", error);
2484         else
2485                 content_debug("error occurred! : %d\n", error);
2486
2487         content_debug("Noti from PID(%d)\n", pid);
2488
2489         if (update_item == MEDIA_ITEM_FILE)
2490                 content_debug("Noti item : MEDIA_ITEM_FILE\n");
2491         else if (update_item == MEDIA_ITEM_DIRECTORY)
2492                 content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n");
2493
2494         if (update_type == MEDIA_CONTENT_INSERT)
2495                 content_debug("Noti type : MEDIA_CONTENT_INSERT\n");
2496         else if (update_type == MEDIA_CONTENT_DELETE)
2497                 content_debug("Noti type : MEDIA_CONTENT_DELETE\n");
2498         else if (update_type == MEDIA_CONTENT_UPDATE)
2499                 content_debug("Noti type : MEDIA_CONTENT_UPDATE\n");
2500
2501         content_debug("content type : %d\n", media_type);
2502
2503         if (path)
2504                 content_debug("path : %s\n", path);
2505         else
2506                 content_debug("path not\n");
2507
2508         if (uuid)
2509                 content_debug("uuid : %s\n", uuid);
2510         else
2511                 content_debug("uuid not\n");
2512
2513         if (mime_type)
2514                 content_debug("mime_type : %s\n", mime_type);
2515         else
2516                 content_debug("mime not\n");
2517
2518         if (user_data) content_debug("String : %s\n", (char *)user_data);
2519
2520         return;
2521 }
2522
2523 void _noti_cb_2(media_content_error_e error,
2524                                 int pid,
2525                                 media_content_db_update_item_type_e update_item,
2526                                 media_content_db_update_type_e update_type,
2527                                 media_content_type_e media_type,
2528                                 char *uuid,
2529                                 char *path,
2530                                 char *mime_type,
2531                                 void *user_data)
2532 {
2533         if (error == 0)
2534                 content_debug("noti_2 success! : %d\n", error);
2535         else
2536                 content_debug("error occurred! : %d\n", error);
2537
2538         content_debug("Noti_2 from PID(%d)\n", pid);
2539
2540         g_main_loop_quit(g_loop);
2541         return;
2542 }
2543
2544 static media_content_noti_h noti_h;
2545 static media_content_noti_h noti_h_2;
2546
2547 gboolean _send_noti_operations(gpointer data)
2548 {
2549         int ret = MEDIA_CONTENT_ERROR_NONE;
2550
2551         /* First of all, noti subscription */
2552         char *user_str = strdup("hi");
2553         media_content_add_db_updated_cb(_noti_cb, (void*)user_str, &noti_h);
2554         media_content_add_db_updated_cb(_noti_cb_2, (void*)user_str, &noti_h_2);
2555
2556         /* media_info_insert_to_db */
2557         media_info_h media_item = NULL;
2558         const char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2559
2560         ret = media_info_insert_to_db(path, &media_item);
2561         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2562                 content_error("media_info_insert_to_db failed : %d", ret);
2563                 media_info_destroy(media_item);
2564                 return FALSE;
2565         }
2566
2567         content_debug("media_info_insert_to_db success");
2568
2569         media_content_remove_db_updated_cb(noti_h);
2570
2571         /* media_info_update_to_db */
2572         ret = media_info_update_to_db(media_item);
2573         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2574                 content_error("media_info_update_to_db failed : %d\n", ret);
2575                 media_info_destroy(media_item);
2576                 return ret;
2577         }
2578
2579         media_info_destroy(media_item);
2580
2581         return FALSE;
2582 }
2583
2584 int test_noti()
2585 {
2586         int ret = MEDIA_CONTENT_ERROR_NONE;
2587         GSource *source = NULL;
2588         GMainContext *context = NULL;
2589
2590         g_loop = g_main_loop_new(NULL, FALSE);
2591         context = g_main_loop_get_context(g_loop);
2592         source = g_idle_source_new();
2593         g_source_set_callback(source, _send_noti_operations, NULL, NULL);
2594         g_source_attach(source, context);
2595
2596         g_main_loop_run(g_loop);
2597         g_main_loop_unref(g_loop);
2598
2599         test_filter_destroy();
2600         media_content_remove_db_updated_cb(noti_h_2);
2601
2602         return ret;
2603 }
2604
2605 bool media_face_test_cb(media_face_h face, void *user_data)
2606 {
2607         get_face_meta(face);
2608
2609         if (user_data != NULL) {
2610                 media_face_h new_face = NULL;
2611                 media_face_clone(&new_face, face);
2612
2613                 GList **list = (GList**)user_data;
2614                 *list = g_list_append(*list, new_face);
2615         }
2616
2617         return true;
2618 }
2619
2620 int test_face(void)
2621 {
2622         int ret = MEDIA_CONTENT_ERROR_NONE;
2623         filter_h filter = NULL;
2624         GList *all_item_list = NULL;
2625         int i = 0;
2626
2627         ret = media_filter_create(&filter);
2628         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
2629
2630         ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", MEDIA_CONTENT_COLLATE_DEFAULT);
2631         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2632                 media_filter_destroy(filter);
2633                 content_error("Fail to set condition");
2634                 return ret;
2635         }
2636
2637         ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
2638         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2639                 content_error("media_info_foreach_media_from_db failed: %d", ret);
2640                 media_filter_destroy(filter);
2641                 return ret;
2642         }
2643
2644         for (i = 0; i < g_list_length(all_item_list); i++) {
2645                 media_info_h media_handle = NULL;
2646                 char *media_id = NULL;
2647                 int face_count = 0;
2648
2649                 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
2650
2651                 ret = media_info_get_media_id(media_handle, &media_id);
2652                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2653                         content_error("media_info_get_media_id failed: %d", ret);
2654
2655                 ret = media_info_get_face_count_from_db(media_id, filter, &face_count);
2656                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2657                         content_error("media_info_get_face_count_from_db failed: %d", ret);
2658
2659                 content_error("media_id [%s] face_count [%d]", media_id, face_count);
2660
2661                 ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, NULL);
2662                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2663                         content_error("media_info_foreach_face_from_db failed: %d", ret);
2664
2665                 media_info_destroy(media_handle);
2666         }
2667
2668         media_filter_destroy(filter);
2669
2670         return ret;
2671 }
2672
2673 int test_face_add_del(void)
2674 {
2675         int ret = MEDIA_CONTENT_ERROR_NONE;
2676         char *media_id = "ecca7366-e085-41d8-a12b-cbdfc2b9c5fc";
2677
2678         /* Insert Test */
2679         media_face_h face = NULL;
2680
2681         char *face_tag = "test_face_tag";
2682
2683         ret = media_face_create(media_id, &face);
2684         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_face_create");
2685
2686         ret = media_face_set_face_rect(face, 10, 12, 50, 100);
2687         if (ret != MEDIA_CONTENT_ERROR_NONE)
2688                 content_error("media_face_set_face_rect failed: %d", ret);
2689
2690         ret = media_face_set_orientation(face, 5);
2691         if (ret != MEDIA_CONTENT_ERROR_NONE)
2692                 content_error("media_face_set_orientation failed: %d", ret);
2693
2694         ret = media_face_set_tag(face, face_tag);
2695         if (ret != MEDIA_CONTENT_ERROR_NONE)
2696                 content_error("media_face_set_tag failed: %d", ret);
2697
2698         ret = media_face_insert_to_db(face);
2699         if (ret != MEDIA_CONTENT_ERROR_NONE)
2700                 content_error("media_face_insert_to_db failed: %d", ret);
2701
2702         ret = media_face_destroy(face);
2703         if (ret != MEDIA_CONTENT_ERROR_NONE)
2704                 content_error("media_face_destroy failed: %d", ret);
2705
2706         /* Update Test */
2707         GList *all_item_list = NULL;
2708         filter_h filter = NULL;
2709         ret = media_filter_create(&filter);
2710         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
2711
2712         ret = media_filter_set_condition(filter, "MEDIA_FACE_TAG IS NOT NULL", MEDIA_CONTENT_COLLATE_DEFAULT);
2713         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2714                 media_filter_destroy(filter);
2715                 content_error("Fail to set condition");
2716                 return ret;
2717         }
2718
2719         ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, &all_item_list);
2720
2721         if (g_list_length(all_item_list) > 0) {
2722                 media_face_h face_handle = NULL;
2723                 face_handle = (media_face_h)g_list_nth_data(all_item_list, 0);
2724
2725                 ret = media_face_set_face_rect(face_handle, 20, 22, 70, 70);
2726                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2727                         content_error("media_face_set_face_rect failed: %d", ret);
2728                 ret = media_face_set_orientation(face_handle, 3);
2729                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2730                         content_error("media_face_set_orientation failed: %d", ret);
2731                 ret = media_face_set_tag(face_handle, NULL);
2732                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2733                         content_error("media_face_set_tag failed: %d", ret);
2734                 ret = media_face_update_to_db(face_handle);
2735                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2736                         content_error("media_face_update_to_db failed: %d", ret);
2737
2738                 media_face_destroy(face_handle);
2739         }
2740
2741         media_filter_destroy(filter);
2742
2743         /* Delete Test */
2744         char *face_id = "5e58a3a8-f0b2-4c29-b799-b49a70dc2313";
2745
2746         /* Delete Test*/
2747         ret = media_face_delete_from_db(face_id);
2748
2749         return ret;
2750 }
2751
2752 #ifdef _USE_TVPD_MODE
2753 filter_h g_tv_filter = NULL;
2754
2755 int test_tv_filter_create(void)
2756 {
2757         content_debug("\n============Filter Create============\n\n");
2758
2759         int ret = MEDIA_CONTENT_ERROR_NONE;
2760
2761         ret = media_filter_create(&g_tv_filter);
2762
2763         ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
2764
2765         ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
2766
2767         return ret;
2768 }
2769
2770 int test_tv_filter_destroy(void)
2771 {
2772         content_debug("\n============Filter Destroy============\n\n");
2773
2774         int ret = MEDIA_CONTENT_ERROR_NONE;
2775
2776         ret = media_filter_destroy(g_tv_filter);
2777
2778         return ret;
2779 }
2780
2781 bool pvr_item_cb(media_pvr_h pvr, void *user_data)
2782 {
2783         int ret = MEDIA_CONTENT_ERROR_NONE;
2784         char *c_value = NULL;
2785         int i_value = 0;
2786         bool b_value = false;
2787         unsigned long long l_value = 0;
2788
2789         if (pvr == NULL) {
2790                 content_debug("NO Item");
2791                 return true;
2792         }
2793
2794         ret = media_pvr_get_media_id(pvr, &c_value);
2795         if (ret != MEDIA_CONTENT_ERROR_NONE)
2796                 content_error("Fail to media_pvr_get_media_id");
2797         content_debug("media_id [%s]", c_value);
2798         SAFE_FREE(c_value);
2799
2800         ret = media_pvr_get_channel_name(pvr, &c_value);
2801         if (ret != MEDIA_CONTENT_ERROR_NONE)
2802                 content_error("Fail to media_pvr_get_channel_name");
2803         content_debug("channel_name [%s]", c_value);
2804         SAFE_FREE(c_value);
2805
2806         ret = media_pvr_get_program_title(pvr, &c_value);
2807         if (ret != MEDIA_CONTENT_ERROR_NONE)
2808                 content_error("Fail to media_pvr_get_program_title");
2809         content_debug("program_title [%s]", c_value);
2810         SAFE_FREE(c_value);
2811
2812         ret = media_pvr_get_program_crid(pvr, &c_value);
2813         if (ret != MEDIA_CONTENT_ERROR_NONE)
2814                 content_error("Fail to media_pvr_get_program_crid");
2815         content_debug("program_crid [%s]", c_value);
2816         SAFE_FREE(c_value);
2817
2818         ret = media_pvr_get_guidance(pvr, &c_value);
2819         if (ret != MEDIA_CONTENT_ERROR_NONE)
2820                 content_error("Fail to media_pvr_get_guidance");
2821         content_debug("guidance [%s]", c_value);
2822         SAFE_FREE(c_value);
2823
2824         ret = media_pvr_get_synopsis(pvr, &c_value);
2825         if (ret != MEDIA_CONTENT_ERROR_NONE)
2826                 content_error("Fail to media_pvr_get_synopsis");
2827         content_debug("synopsis [%s]", c_value);
2828         SAFE_FREE(c_value);
2829
2830         ret = media_pvr_get_genre(pvr, &c_value);
2831         if (ret != MEDIA_CONTENT_ERROR_NONE)
2832                 content_error("Fail to media_pvr_get_synopsis");
2833         content_debug("genre [%s]", c_value);
2834         SAFE_FREE(c_value);
2835
2836         ret = media_pvr_get_language(pvr, &c_value);
2837         if (ret != MEDIA_CONTENT_ERROR_NONE)
2838                 content_error("Fail to media_pvr_get_language");
2839         content_debug("language [%s]", c_value);
2840         SAFE_FREE(c_value);
2841
2842         ret = media_pvr_get_path(pvr, &c_value);
2843         if (ret != MEDIA_CONTENT_ERROR_NONE)
2844                 content_error("Fail to media_pvr_get_path");
2845         content_debug("path [%s]", c_value);
2846         SAFE_FREE(c_value);
2847
2848         ret = media_pvr_get_storage_id(pvr, &c_value);
2849         if (ret != MEDIA_CONTENT_ERROR_NONE)
2850                 content_error("Fail to media_pvr_get_storage_id");
2851         content_debug("storage_id [%s]", c_value);
2852         SAFE_FREE(c_value);
2853
2854         ret = media_pvr_get_size(pvr, &l_value);
2855         if (ret != MEDIA_CONTENT_ERROR_NONE)
2856                 content_error("Fail to media_pvr_get_size");
2857         content_debug("size [%lld]", l_value);
2858
2859         ret = media_pvr_get_timezone(pvr, &i_value);
2860         if (ret != MEDIA_CONTENT_ERROR_NONE)
2861                 content_error("Fail to media_pvr_get_timezone");
2862         content_debug("timezone [%d]", i_value);
2863
2864         ret = media_pvr_get_ptc(pvr, &i_value);
2865         if (ret != MEDIA_CONTENT_ERROR_NONE)
2866                 content_error("Fail to media_pvr_get_ptc");
2867         content_debug("ptc [%d]", i_value);
2868
2869         ret = media_pvr_get_major(pvr, &i_value);
2870         if (ret != MEDIA_CONTENT_ERROR_NONE)
2871                 content_error("Fail to media_pvr_get_major");
2872         content_debug("[%d]", i_value);
2873
2874         ret = media_pvr_get_minor(pvr, &i_value);
2875         if (ret != MEDIA_CONTENT_ERROR_NONE)
2876                 content_error("Fail to media_pvr_get_minor");
2877         content_debug("minor [%d]", i_value);
2878
2879         ret = media_pvr_get_channel_type(pvr, &i_value);
2880         if (ret != MEDIA_CONTENT_ERROR_NONE)
2881                 content_error("Fail to media_pvr_get_channel_type");
2882         content_debug("channel_type [%d]", i_value);
2883
2884         ret = media_pvr_get_program_num(pvr, &i_value);
2885         if (ret != MEDIA_CONTENT_ERROR_NONE)
2886                 content_error("Fail to media_pvr_get_program_num");
2887         content_debug("program_num [%d]", i_value);
2888
2889         unsigned int ui_value = 0;
2890         ret = media_pvr_get_service_profile(pvr, &ui_value);
2891         if (ret != MEDIA_CONTENT_ERROR_NONE)
2892                 content_error("Fail to media_pvr_get_service_profile");
2893         content_debug("service_profile [%u]", ui_value);
2894
2895         ret = media_pvr_get_duration(pvr, &i_value);
2896         if (ret != MEDIA_CONTENT_ERROR_NONE)
2897                 content_error("Fail to media_pvr_get_duration");
2898         content_debug("duration [%d]", i_value);
2899
2900         ret = media_pvr_get_embargo_time(pvr, &i_value);
2901         if (ret != MEDIA_CONTENT_ERROR_NONE)
2902                 content_error("Fail to media_pvr_get_embargo_time");
2903         content_debug("embargo_time [%d]", i_value);
2904
2905         ret = media_pvr_get_expiry_time(pvr, &i_value);
2906         if (ret != MEDIA_CONTENT_ERROR_NONE)
2907                 content_error("Fail to media_pvr_get_expiry_time");
2908         content_debug("expiry_time [%d]", i_value);
2909
2910         ret = media_pvr_get_parental_rating(pvr, &i_value);
2911         if (ret != MEDIA_CONTENT_ERROR_NONE)
2912                 content_error("Fail to media_pvr_get_parental_rating");
2913         content_debug("parental_rating [%d]", i_value);
2914
2915         ret = media_pvr_get_start_time(pvr, &i_value);
2916         if (ret != MEDIA_CONTENT_ERROR_NONE)
2917                 content_error("Fail to media_pvr_get_start_time");
2918         content_debug("start_time [%d]", i_value);
2919
2920         ret = media_pvr_get_program_start_time(pvr, &i_value);
2921         if (ret != MEDIA_CONTENT_ERROR_NONE)
2922                 content_error("Fail to media_pvr_get_program_start_time");
2923         content_debug("program_start_time [%d]", i_value);
2924
2925         ret = media_pvr_get_program_end_time(pvr, &i_value);
2926         if (ret != MEDIA_CONTENT_ERROR_NONE)
2927                 content_error("Fail to media_pvr_get_program_end_time");
2928         content_debug("program_end_time [%d]", i_value);
2929
2930         ret = media_pvr_get_program_date(pvr, &i_value);
2931         if (ret != MEDIA_CONTENT_ERROR_NONE)
2932                 content_error("Fail to media_pvr_get_program_date");
2933         content_debug("program_date [%d]", i_value);
2934
2935         ret = media_pvr_get_timer_record(pvr, &b_value);
2936         if (ret != MEDIA_CONTENT_ERROR_NONE)
2937                 content_error("Fail to media_pvr_get_timer_record");
2938         content_debug("timer_record [%d]", b_value);
2939
2940         ret = media_pvr_get_series_record(pvr, &b_value);
2941         if (ret != MEDIA_CONTENT_ERROR_NONE)
2942                 content_error("Fail to media_pvr_get_series_record");
2943         content_debug("series_record [%d]", b_value);
2944
2945         ret = media_pvr_get_hd(pvr, &i_value);
2946         if (ret != MEDIA_CONTENT_ERROR_NONE)
2947                 content_error("Fail to media_pvr_get_hd");
2948         content_debug("hd [%d]", i_value);
2949
2950         ret = media_pvr_get_subtitle(pvr, &b_value);
2951         if (ret != MEDIA_CONTENT_ERROR_NONE)
2952                 content_error("Fail to media_pvr_get_subtitle");
2953         content_debug("subtitle [%d]", b_value);
2954
2955         ret = media_pvr_get_ttx(pvr, &b_value);
2956         if (ret != MEDIA_CONTENT_ERROR_NONE)
2957                 content_error("Fail to media_pvr_get_ttx");
2958         content_debug("ttx [%d]", b_value);
2959
2960         ret = media_pvr_get_ad(pvr, &b_value);
2961         if (ret != MEDIA_CONTENT_ERROR_NONE)
2962                 content_error("Fail to media_pvr_get_ad");
2963         content_debug("ad [%d]", b_value);
2964
2965         ret = media_pvr_get_hard_of_hearing_radio(pvr, &b_value);
2966         if (ret != MEDIA_CONTENT_ERROR_NONE)
2967                 content_error("Fail to media_pvr_get_hard_of_hearing_radio");
2968         content_debug("hard_of_hearing_radio [%d]", b_value);
2969
2970         ret = media_pvr_get_data_service(pvr, &b_value);
2971         if (ret != MEDIA_CONTENT_ERROR_NONE)
2972                 content_error("Fail to media_pvr_get_data_service");
2973         content_debug("data_service [%d]", b_value);
2974
2975         ret = media_pvr_get_content_lock(pvr, &b_value);
2976         if (ret != MEDIA_CONTENT_ERROR_NONE)
2977                 content_error("Fail to media_pvr_get_content_lock");
2978         content_debug("content_lock [%d]", b_value);
2979
2980         ret = media_pvr_get_content_watch(pvr, &b_value);
2981         if (ret != MEDIA_CONTENT_ERROR_NONE)
2982                 content_error("Fail to media_pvr_get_content_watch");
2983         content_debug("content_watch [%d]", b_value);
2984
2985         ret = media_pvr_get_has_audio_only(pvr, &b_value);
2986         if (ret != MEDIA_CONTENT_ERROR_NONE)
2987                 content_error("Fail to media_pvr_get_has_audio_only");
2988         content_debug("has_audio_only [%d]", b_value);
2989
2990         ret = media_pvr_get_is_local_record(pvr, &b_value);
2991         if (ret != MEDIA_CONTENT_ERROR_NONE)
2992                 content_error("Fail to media_pvr_get_is_local_record");
2993         content_debug("is_local_record [%d]", b_value);
2994
2995         ret = media_pvr_get_resolution(pvr, (media_pvr_resolution_e*)&i_value);
2996         if (ret != MEDIA_CONTENT_ERROR_NONE)
2997                 content_error("Fail to media_pvr_get_resolution");
2998         content_debug("resolution [%d]", i_value);
2999
3000         ret = media_pvr_get_aspectratio(pvr, (media_pvr_aspectratio_e*)&i_value);
3001         if (ret != MEDIA_CONTENT_ERROR_NONE)
3002                 content_error("Fail to media_pvr_get_aspectratio");
3003         content_debug("aspectratio [%d]", i_value);
3004
3005         ret = media_pvr_get_highlight(pvr, &b_value);
3006         if (ret != MEDIA_CONTENT_ERROR_NONE)
3007                 content_error("Fail to media_pvr_get_highlight");
3008         content_debug("highlight [%d]", b_value);
3009
3010
3011         return TRUE;
3012 }
3013
3014 int test_pvr()
3015 {
3016         int ret = MEDIA_CONTENT_ERROR_NONE;
3017         int media_count = 0;
3018
3019         content_debug("\n============PVR Test============\n\n");
3020
3021         test_tv_filter_create();
3022
3023         ret = media_pvr_get_media_count_from_db(g_tv_filter, &media_count);
3024         if (ret != MEDIA_CONTENT_ERROR_NONE)
3025                 content_error("media_pvr_get_media_count_from_db failed: %d", ret);
3026         else
3027                 content_debug("media_count : [%d]", media_count);
3028
3029         ret = media_pvr_foreach_media_from_db(g_tv_filter, pvr_item_cb, NULL);
3030         if (ret != MEDIA_CONTENT_ERROR_NONE)
3031                 content_error("media_pvr_foreach_media_from_db is failed");
3032
3033         test_tv_filter_destroy();
3034
3035         return ret;
3036 }
3037
3038 int test_pvr_update_db(void)
3039 {
3040         int ret = MEDIA_CONTENT_ERROR_NONE;
3041         media_pvr_h pvr = NULL;
3042
3043         ret = media_pvr_get_pvr_from_db("ff9b5a9a-a7b4-47f4-8255-84e007e25f13", &pvr);
3044         if (ret != MEDIA_CONTENT_ERROR_NONE)
3045                 content_error("media_pvr_get_pvr_from_db failed: %d", ret);
3046
3047         ret = media_pvr_set_content_lock(pvr, TRUE);
3048         if (ret != MEDIA_CONTENT_ERROR_NONE)
3049                 content_error("Fail to media_pvr_set_content_lock");
3050
3051         ret = media_pvr_set_content_watch(pvr, TRUE);
3052         if (ret != MEDIA_CONTENT_ERROR_NONE)
3053                 content_error("Fail to media_pvr_set_content_watch");
3054
3055         ret = media_pvr_set_program_title(pvr, "TEST TITLE");
3056         if (ret != MEDIA_CONTENT_ERROR_NONE)
3057                 content_error("Fail to media_pvr_set_program_title");
3058
3059         ret = media_pvr_set_highlight(pvr, TRUE);
3060         if (ret != MEDIA_CONTENT_ERROR_NONE)
3061                 content_error("Fail to media_pvr_set_highlight");
3062
3063         ret = media_pvr_update_to_db(pvr);
3064         if (ret != MEDIA_CONTENT_ERROR_NONE)
3065                 content_error("Fail to media_pvr_update_to_db");
3066
3067         if (pvr != NULL)
3068                 media_pvr_destroy(pvr);
3069
3070         return ret;
3071 }
3072 #endif
3073
3074 int main(int argc, char *argv[])
3075 {
3076         int ret = MEDIA_CONTENT_ERROR_NONE;
3077
3078         content_debug("--- content manager test start ---\n\n");
3079
3080         ret = test_connect_database();
3081         if (ret != MEDIA_CONTENT_ERROR_NONE)
3082                 return MEDIA_CONTENT_ERROR_NONE;
3083 #ifdef _USE_TVPD_MODE
3084         test_pvr();
3085
3086         test_pvr_update_db();
3087
3088         test_pvr();
3089 #endif
3090
3091 #if 0
3092         if (argc == 2) {
3093                 ret = test_ebook_text_finder(argv[1]);
3094                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3095                         return ret;
3096         }
3097
3098         ret = test_start_face_detection(FALSE);
3099         if (ret != MEDIA_CONTENT_ERROR_NONE)
3100                 return ret;
3101
3102         ret = test_move();
3103         if (ret != MEDIA_CONTENT_ERROR_NONE)
3104                 return ret;
3105
3106         ret = test_gallery_scenario();
3107         if (ret != MEDIA_CONTENT_ERROR_NONE)
3108                 return ret;
3109
3110         ret = test_get_all_music_files();
3111         if (ret != MEDIA_CONTENT_ERROR_NONE)
3112                 return ret;
3113
3114         ret = test_media_info_operation();
3115         if (ret != MEDIA_CONTENT_ERROR_NONE)
3116                 return ret;
3117
3118         ret = test_folder_operation();
3119         if (ret != MEDIA_CONTENT_ERROR_NONE)
3120                 return ret;
3121
3122         ret = test_playlist_operation();
3123         if (ret != MEDIA_CONTENT_ERROR_NONE)
3124                 return ret;
3125
3126         ret = test_tag_operation();
3127         if (ret != MEDIA_CONTENT_ERROR_NONE)
3128                 return ret;
3129
3130         ret = test_bookmark_operation();
3131         if (ret != MEDIA_CONTENT_ERROR_NONE)
3132                 return ret;
3133
3134         ret = test_album_list();
3135         if (ret != MEDIA_CONTENT_ERROR_NONE)
3136                 return ret;
3137
3138         ret = test_group_operation();
3139         if (ret != MEDIA_CONTENT_ERROR_NONE)
3140                 return ret;
3141
3142         ret = test_update_operation();
3143         if (ret != MEDIA_CONTENT_ERROR_NONE)
3144                 return ret;
3145
3146         ret = test_insert();
3147         if (ret != MEDIA_CONTENT_ERROR_NONE)
3148                 return ret;
3149
3150         ret = test_move();
3151         if (ret != MEDIA_CONTENT_ERROR_NONE)
3152                 return ret;
3153
3154         if (argc == 2) {
3155                 ret = test_create_thumbnail(argv[1]);
3156                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3157                         return ret;
3158         }
3159
3160         ret = test_extrace_face(TRUE);
3161         if (ret != MEDIA_CONTENT_ERROR_NONE)
3162                 return ret;
3163
3164         ret = test_request_update_db();
3165         if (ret != MEDIA_CONTENT_ERROR_NONE)
3166                 return ret;
3167
3168         ret = DFT_test();
3169         if (ret != MEDIA_CONTENT_ERROR_NONE)
3170                 return ret;
3171
3172         ret = test_batch_operations();
3173         if (ret != MEDIA_CONTENT_ERROR_NONE)
3174                 return MEDIA_CONTENT_ERROR_NONE;
3175
3176         ret = test_scan_file();
3177         if (ret != MEDIA_CONTENT_ERROR_NONE)
3178                 return MEDIA_CONTENT_ERROR_NONE;
3179
3180         ret = test_scan_dir(true);
3181         if (ret != MEDIA_CONTENT_ERROR_NONE)
3182                 return MEDIA_CONTENT_ERROR_NONE;
3183
3184         ret = test_noti();
3185         if (ret != MEDIA_CONTENT_ERROR_NONE)
3186                 return MEDIA_CONTENT_ERROR_NONE;
3187
3188         ret = test_face();
3189         if (ret != MEDIA_CONTENT_ERROR_NONE)
3190                 return MEDIA_CONTENT_ERROR_NONE;
3191
3192         ret = test_face_add_del();
3193         if (ret != MEDIA_CONTENT_ERROR_NONE)
3194                 return MEDIA_CONTENT_ERROR_NONE;
3195
3196         ret = test_playlist_operation_v2();
3197         if (ret != MEDIA_CONTENT_ERROR_NONE)
3198                 return MEDIA_CONTENT_ERROR_NONE;
3199
3200         ret = test_bookmark_operation_v2();
3201         if (ret != MEDIA_CONTENT_ERROR_NONE)
3202                 return MEDIA_CONTENT_ERROR_NONE;
3203
3204         ret = test_tag_operation_v2();
3205         if (ret != MEDIA_CONTENT_ERROR_NONE)
3206                 return MEDIA_CONTENT_ERROR_NONE;
3207 #endif
3208
3209         ret = test_disconnect_database();
3210         if (ret != MEDIA_CONTENT_ERROR_NONE)
3211                 return ret;
3212
3213         content_debug("--- content manager test end ---\n");
3214
3215         return ret;
3216 }