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