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