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