45e34193d083211104239dc3cdd7f667209c0291
[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         /*const char *condition = "MEDIA_TYPE IS NOT 0 AND MEDIA_DESCRIPTION IS NOT NULL"; */   /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
921
922         ret = media_filter_create(&g_filter);
923
924         /* Set condition and collate
925          * Condition string : You can make where statement of sql.
926          * Colation : You can use collation when comparing.
927          * Ex) In case of FILE_NAME='Samsung' as condition string,
928          *      if you want to compare with NOCASE collation,
929          *      call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
930          *      if you want to compare in case-sensitive,
931          *      call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
932          */
933         ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
934
935         /* Collation of ordering
936          * If you want to get list, which is sorted by NOCASE,
937          * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_NOCASE);
938          * Or,
939          * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
940          */
941         /* Able to set multi column to set order */
942 #if 0
943         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, "MEDIA_MODIFIED_TIME, MEDIA_DISPLAY_NAME", MEDIA_CONTENT_COLLATE_DEFAULT);
944         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
945         ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TRACK_NUM_INT, MEDIA_CONTENT_COLLATE_DEFAULT);
946         ret = media_filter_set_storage(g_filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e");
947
948         /* Filter for group */
949         const char *g_condition = "TAG_NAME like \"\%my\%\"";
950         const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
951 #endif
952         ret = media_filter_create(&g_filter_g);
953
954         ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
955
956         return ret;
957 }
958
959 int test_filter_destroy(void)
960 {
961         content_debug("\n============Filter Create============\n\n");
962
963         int ret = MEDIA_CONTENT_ERROR_NONE;
964
965         ret = media_filter_destroy(g_filter);
966
967         return ret;
968 }
969
970 int test_connect_database(void)
971 {
972         int ret = MEDIA_CONTENT_ERROR_NONE;
973
974         content_debug("\n============DB Connection Test============\n\n");
975
976         ret = media_content_connect();
977
978         if (ret == MEDIA_CONTENT_ERROR_NONE)
979                 content_debug("connection is success\n\n");
980         else
981                 content_error("connection is failed\n\n");
982
983         return ret;
984 }
985
986 int test_gallery_scenario(void)
987 {
988         int ret = MEDIA_CONTENT_ERROR_NONE;
989         unsigned int i = 0;
990         filter_h filter = NULL;
991
992         int count;
993         GList *folder_list = NULL;
994         media_folder_h folder_handle = NULL;
995
996         /* First, Get folder list */
997         ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
998         if (ret != MEDIA_CONTENT_ERROR_NONE) {
999                 content_error("media_folder_foreach_folder_from_db failed: %d", ret);
1000                 return -1;
1001         } else {
1002                 content_debug("media_folder_foreach_folder_from_db success!!");
1003                 char *folder_id = NULL;
1004
1005                 for (i = 0; i < g_list_length(folder_list); i++) {
1006                         folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
1007
1008                         get_folder_meta(folder_handle, &folder_id);
1009
1010                         ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
1011                         SAFE_FREE(folder_id);
1012                         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1013                                 content_error("media_folder_get_media_count_from_db failed: %d", ret);
1014                                 return -1;
1015                         } else {
1016                                 content_debug("media count [%d] : %d", i, count);
1017                         }
1018                 }
1019         }
1020
1021         /* To check performance */
1022         struct timeval start, end;
1023         gettimeofday(&start, NULL);
1024
1025         /* Second, Get all item list */
1026         media_info_h media_handle = NULL;
1027         GList *all_item_list = NULL;
1028
1029         media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
1030         media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
1031         ret = media_filter_create(&filter);
1032         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1033                 content_error("Fail to create filter");
1034                 return ret;
1035         }
1036         ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
1037         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1038                 media_filter_destroy(filter);
1039                 content_error("Fail to set condition");
1040                 return ret;
1041         }
1042         ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
1043         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1044                 media_filter_destroy(filter);
1045                 content_error("Fail to set order");
1046                 return ret;
1047         }
1048
1049         ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
1050         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1051                 content_error("media_info_foreach_media_from_db failed: %d", ret);
1052                 media_filter_destroy(filter);
1053                 return -1;
1054         } else {
1055                 content_debug("media_info_foreach_media_from_db success");
1056
1057                 for (i = 0; i < g_list_length(all_item_list); i++) {
1058                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
1059                         get_media_meta(media_handle);
1060                 }
1061         }
1062
1063         media_filter_destroy(filter);
1064         filter = NULL;
1065
1066         /* To check performance */
1067         gettimeofday(&end, NULL);
1068         long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
1069         content_debug("Time : %ld\n", time);
1070
1071         /* Third, Get item list of a folder */
1072         GList *item_list = NULL;
1073
1074         for (i = 0; i < g_list_length(folder_list); i++) {
1075                 unsigned int j = 0;
1076                 char *folder_id = NULL;
1077                 folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
1078
1079                 get_folder_meta(folder_handle, &folder_id);
1080
1081                 ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
1082                 SAFE_FREE(folder_id);
1083
1084                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1085                         content_error("media_folder_foreach_media_from_db failed: %d", ret);
1086                         return -1;
1087                 } else {
1088                         content_error("media_folder_foreach_media_from_db success!");
1089
1090                         for (j = 0; j < g_list_length(item_list); j++) {
1091                                 media_handle = (media_info_h)g_list_nth_data(item_list, j);
1092                                 get_media_meta(media_handle);
1093                         }
1094                 }
1095         }
1096
1097         /* Get tag list */
1098         media_tag_h tag_handle = NULL;
1099         GList *tag_list = NULL;
1100         GList *media_list_in_tag = NULL;
1101         int tag_id = 0;
1102
1103         ret = media_tag_foreach_tag_from_db(filter, gallery_tag_item_cb, &tag_list);
1104
1105         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1106                 content_error("media_tag_foreach_tag_from_db failed: %d", ret);
1107                 return -1;
1108         } else {
1109                 content_error("media_tag_foreach_tag_from_db success");
1110                 for (i = 0; i < g_list_length(tag_list); i++) {
1111                         tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
1112                         get_tag_meta(tag_handle);
1113
1114                         ret = media_tag_get_tag_id(tag_handle, &tag_id);
1115                         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1116                                 ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag);
1117                                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1118                                         content_error("media_tag_foreach_media_from_db failed: %d", ret);
1119                                         return -1;
1120                                 } else {
1121                                         content_error("media_tag_foreach_media_from_db success");
1122                                         unsigned int j = 0;
1123                                         media_info_h tag_media_handle;
1124
1125                                         for (j = 0; j < g_list_length(media_list_in_tag); j++) {
1126                                                 tag_media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, j);
1127                                                 get_media_meta(tag_media_handle);
1128                                         }
1129                                 }
1130                         }
1131                 }
1132         }
1133
1134         /* Remove folder list */
1135         if (folder_list) {
1136                 for (i = 0; i < g_list_length(folder_list); i++) {
1137                         folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
1138                         media_folder_destroy(folder_handle);
1139                 }
1140
1141                 g_list_free(folder_list);
1142         }
1143
1144         /* Remove all items list */
1145         if (all_item_list) {
1146                 for (i = 0; i < g_list_length(all_item_list); i++) {
1147                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
1148                         ret = media_info_destroy(media_handle);
1149                         if (ret != MEDIA_CONTENT_ERROR_NONE)
1150                                 content_error("media_info_destroy failed: %d", ret);
1151                 }
1152
1153                 g_list_free(all_item_list);
1154         }
1155
1156         /* Remove items list */
1157         if (item_list) {
1158                 for (i = 0; i < g_list_length(item_list); i++) {
1159                         media_handle = (media_info_h)g_list_nth_data(item_list, i);
1160                         ret = media_info_destroy(media_handle);
1161                         if (ret != MEDIA_CONTENT_ERROR_NONE)
1162                                 content_error("media_info_destroy failed: %d", ret);
1163                 }
1164
1165                 g_list_free(item_list);
1166         }
1167
1168         /* Remove tag list */
1169         if (tag_list) {
1170                 for (i = 0; i < g_list_length(tag_list); i++) {
1171                         tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
1172                         ret = media_tag_destroy(tag_handle);
1173                         if (ret != MEDIA_CONTENT_ERROR_NONE)
1174                                 content_error("error media_tag_destroy : [%d]", ret);
1175                 }
1176
1177                 g_list_free(tag_list);
1178         }
1179
1180         /* Remove media list in a tag */
1181         if (media_list_in_tag) {
1182                 for (i = 0; i < g_list_length(media_list_in_tag); i++) {
1183                         media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, i);
1184                         ret = media_info_destroy(media_handle);
1185                         if (ret != MEDIA_CONTENT_ERROR_NONE)
1186                                 content_error("media_info_destroy failed: %d", ret);
1187                 }
1188
1189                 g_list_free(media_list_in_tag);
1190         }
1191
1192         return MEDIA_CONTENT_ERROR_NONE;
1193 }
1194
1195 /*Get All Music file. sort by Title and not case sensitive*/
1196 int test_get_all_music_files(void)
1197 {
1198         int ret = MEDIA_CONTENT_ERROR_NONE;
1199         int media_count = 0;
1200         filter_h filter;
1201
1202         /*Set Filter*/
1203         const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1204
1205         ret = media_filter_create(&filter);
1206         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1207                 content_error("Fail to create filter");
1208                 return ret;
1209         }
1210         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED);
1211         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1212                 media_filter_destroy(filter);
1213                 content_error("Fail to set condition");
1214                 return ret;
1215         }
1216         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED);
1217         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1218                 media_filter_destroy(filter);
1219                 content_error("Fail to set order");
1220                 return ret;
1221         }
1222
1223         /*Get Media Count*/
1224         ret = media_info_get_media_count_from_db(filter, &media_count);
1225         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1226                 media_filter_destroy(filter);
1227                 content_error("Fail to get media count");
1228                 return ret;
1229         }
1230
1231         content_debug("media_count : [%d]", media_count);
1232
1233         ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
1234         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1235                 media_filter_destroy(filter);
1236                 content_error("Fail to get media");
1237                 return ret;
1238         }
1239
1240         ret = media_filter_destroy(filter);
1241
1242         return ret;
1243 }
1244
1245 int test_media_info_operation(void)
1246 {
1247         int ret = MEDIA_CONTENT_ERROR_NONE;
1248         int media_count = 0;
1249
1250         content_debug("\n============Media info Test============\n\n");
1251
1252         test_filter_create();
1253
1254         ret = media_info_get_media_count_from_db(g_filter, &media_count);
1255         if (ret != MEDIA_CONTENT_ERROR_NONE)
1256                 content_error("media_info_get_media_count_from_db failed: %d", ret);
1257         else
1258                 content_debug("media_count : [%d]", media_count);
1259
1260         ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
1261         if (ret == MEDIA_CONTENT_ERROR_NONE)
1262                 content_debug("media_info_foreach_media_from_db is success");
1263         else
1264                 content_error("media_info_foreach_media_from_db is failed");
1265
1266         test_filter_destroy();
1267
1268         return ret;
1269 }
1270
1271 int test_media_info_operation_2(void)
1272 {
1273         int ret = MEDIA_CONTENT_ERROR_NONE;
1274         int bookmark_count = 0;
1275
1276         content_debug("\n============Media info Test 2============\n\n");
1277
1278         test_filter_create();
1279
1280 #if 0
1281         /* Bookmark */
1282         char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1283         media_bookmark_insert_to_db(test_video_id, 100, thumbnail_path1);
1284         media_bookmark_insert_to_db(test_video_id, 200, thumbnail_path1);
1285
1286         media_info_get_bookmark_count_from_db(test_video_id, g_filter_g, &bookmark_count);
1287
1288         content_debug("bookmark_count : [%d]", bookmark_count);
1289
1290         ret = media_info_foreach_bookmark_from_db(test_video_id, g_filter_g, bookmarks_cb, NULL);
1291 #endif
1292
1293         /* Tag */
1294         ret = media_info_get_tag_count_from_db(test_audio_id, g_filter_g, &bookmark_count);
1295         if (ret != MEDIA_CONTENT_ERROR_NONE)
1296                 content_error("media_info_get_tag_count_from_db failed: %d", ret);
1297         else
1298                 content_debug("tag_count : [%d]", bookmark_count);
1299
1300         ret = media_info_foreach_tag_from_db(test_audio_id, g_filter_g, tag_list_cb, NULL);
1301         if (ret != MEDIA_CONTENT_ERROR_NONE)
1302                 content_error("media_info_foreach_tag_from_db failed: %d", ret);
1303
1304         test_filter_destroy();
1305
1306         return ret;
1307 }
1308
1309 int test_folder_operation(void)
1310 {
1311         int ret = MEDIA_CONTENT_ERROR_NONE;
1312         filter_h filter = NULL;
1313         media_folder_h folder = NULL;
1314         char *folder_id = NULL;
1315         int count = 0;
1316
1317         content_debug("\n============Folder Test============\n\n");
1318
1319         test_filter_create();
1320
1321         ret = media_filter_create(&filter);
1322         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1323                 content_error("[ERROR] media_folder_filter_create is failed");
1324                 return ret;
1325         }
1326
1327         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*/
1328         media_filter_set_offset(filter, 0, 5);
1329         media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1330         media_filter_set_storage(filter, "cfbf3d2c-71c5-4611-bccc-7cbac890146e");
1331
1332         ret = media_folder_get_folder_count_from_db(filter, &count);
1333         content_debug("Folder count : [%d]", count);
1334
1335         ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
1336
1337         filter_h m_filter = NULL;
1338
1339         ret = media_filter_create(&m_filter);
1340         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1341                 test_filter_destroy();
1342                 media_filter_destroy(filter);
1343                 content_error("[ERROR] media_info_filter_create is failed");
1344                 return ret;
1345         }
1346
1347         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*/
1348         media_filter_set_offset(m_filter, 0, 5);
1349         media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
1350
1351         ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
1352         if (ret != MEDIA_CONTENT_ERROR_NONE)
1353                 content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret);
1354
1355         media_filter_destroy(filter);
1356         media_filter_destroy(m_filter);
1357
1358         test_filter_destroy();
1359
1360         /* fix prevent: Resource Leak */
1361         SAFE_FREE(folder_id);
1362
1363         return ret;
1364 }
1365
1366 int test_playlist_operation(void)
1367 {
1368         int ret = MEDIA_CONTENT_ERROR_NONE;
1369         media_playlist_h playlist_1 = NULL;
1370         media_playlist_h playlist_2 = NULL;
1371         media_playlist_h playlist_3 = NULL;
1372         media_playlist_h playlist_4 = NULL;
1373         int playlist_id_1 = 0;
1374         int playlist_id_2 = 0;
1375         int playlist_id_3 = 0;
1376         const char *playlist_name_1 = "myPlaylist_1";
1377         const char *playlist_name_2 = "myPlaylist_2";
1378         const char *playlist_name_3 = "myPlaylist_3";
1379         int playlist_count = 0;
1380         int media_count = 0;
1381         int order_1 = 0;
1382         int order_2 = 0;
1383         int order_3 = 0;
1384         int order_4 = 0;
1385         int order_5 = 0;
1386         filter_h filter = NULL;
1387         filter_h m_filter = NULL;
1388
1389         content_debug("\n============Playlist Test============\n\n");
1390
1391         /* Filter for playlist */
1392
1393         const char *condition = "(MEDIA_TYPE=1 or MEDIA_TYPE=3)";       /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1394
1395         ret = media_filter_create(&filter);
1396         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
1397         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_NAME, MEDIA_CONTENT_COLLATE_NOCASE);
1398
1399         /* Create Playlist */
1400         media_playlist_insert_to_db(playlist_name_1, &playlist_1);
1401         media_playlist_insert_to_db(playlist_name_2, &playlist_2);
1402         media_playlist_insert_to_db(playlist_name_3, &playlist_3);
1403
1404         if (playlist_1 != NULL) {
1405                 /* Add media to Playlist */
1406                 media_playlist_add_media(playlist_1, test_audio_id);
1407                 media_playlist_add_media(playlist_1, test_audio_id);
1408                 media_playlist_add_media(playlist_1, test_video_id);
1409
1410                 #if 0
1411                 char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg"));
1412                 media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1413                 #endif
1414
1415                 media_playlist_update_to_db(playlist_1);
1416         }
1417
1418         if (playlist_2 != NULL) {
1419                 media_playlist_add_media(playlist_2, test_audio_id);
1420                 media_playlist_add_media(playlist_2, test_audio_id);
1421                 media_playlist_update_to_db(playlist_2);
1422         }
1423
1424         /* Get Playlist Count*/
1425         ret = media_playlist_get_playlist_count_from_db(filter, &playlist_count);
1426         if (ret == 0)
1427                 content_debug("playlist_count [%d]", playlist_count);
1428
1429         /* Get Playlist*/
1430         GList *playlist_id_list = NULL;
1431         media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, &playlist_id_list);
1432         /* 64bit build issue */
1433 #if 0
1434         /* Get Playlist id*/
1435         playlist_id_1 = (int)g_list_nth_data(playlist_id_list, 0);
1436         playlist_id_2 = (int)g_list_nth_data(playlist_id_list, 1);
1437         playlist_id_3 = (int)g_list_nth_data(playlist_id_list, 2);
1438 #endif
1439         content_debug("playlist_id_1 [%d]", playlist_id_1);
1440         content_debug("playlist_id_2 [%d]", playlist_id_2);
1441         content_debug("playlist_id_3 [%d]", playlist_id_3);
1442
1443         /* Export and import playlist */
1444         media_playlist_export_to_file(playlist_3, tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"));
1445         media_playlist_import_from_file(tzplatform_mkpath(TZ_USER_MUSIC, "playlist.m3u"), "playlist_4", &playlist_4);
1446
1447         /* Filter for media*/
1448         ret = media_filter_create(&m_filter);
1449
1450         ret = media_filter_set_condition(m_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1451
1452         ret = media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_MEMBER_ORDER, MEDIA_CONTENT_COLLATE_DEFAULT);
1453
1454         /* Get media count */
1455         media_playlist_get_media_count_from_db(playlist_id_1, m_filter, &media_count);
1456         content_debug("playlist_1_media_count [%d]", media_count);
1457
1458         media_playlist_get_media_count_from_db(playlist_id_2, m_filter, &media_count);
1459         content_debug("playlist_2_media_count [%d]", media_count);
1460
1461         media_playlist_get_media_count_from_db(playlist_id_3, m_filter, &media_count);
1462         content_debug("playlist_3_media_count [%d]", media_count);
1463
1464         /* Get media of playlist */
1465         GList *playlist_member_id_list = NULL;
1466         GList *playlist_member_id_list_1 = NULL;
1467
1468         media_playlist_foreach_media_from_db(playlist_id_1, m_filter, playlist_item_cb, &playlist_member_id_list);
1469         media_playlist_foreach_media_from_db(playlist_id_2, m_filter, playlist_item_cb, &playlist_member_id_list_1);
1470
1471         int playlist_member_id_1_1 = 0;
1472         int playlist_member_id_1_2 = 0;
1473         int playlist_member_id_1_3 = 0;
1474         int playlist_member_id_2_1 = 0;
1475         int playlist_member_id_2_2 = 0;
1476         /* 64bit build issue */
1477 #if 0
1478         playlist_member_id_1_1 = (int)g_list_nth_data(playlist_member_id_list, 0);
1479         playlist_member_id_1_2 = (int)g_list_nth_data(playlist_member_id_list, 1);
1480         playlist_member_id_1_3 = (int)g_list_nth_data(playlist_member_id_list, 2);
1481         playlist_member_id_2_1 = (int)g_list_nth_data(playlist_member_id_list_1, 0);
1482         playlist_member_id_2_2 = (int)g_list_nth_data(playlist_member_id_list_1, 1);
1483 #endif
1484         content_debug("playlist_member_id_1_1 [%d]", playlist_member_id_1_1);
1485         content_debug("playlist_member_id_1_2 [%d]", playlist_member_id_1_2);
1486         content_debug("playlist_member_id_1_3 [%d]", playlist_member_id_1_3);
1487         content_debug("playlist_member_id_2_1 [%d]", playlist_member_id_2_1);
1488         content_debug("playlist_member_id_2_2 [%d]", playlist_member_id_2_2);
1489
1490         media_playlist_get_play_order(playlist_1, playlist_member_id_1_1, &order_1);
1491         media_playlist_get_play_order(playlist_1, playlist_member_id_1_2, &order_2);
1492         media_playlist_get_play_order(playlist_1, playlist_member_id_1_3, &order_3);
1493         media_playlist_get_play_order(playlist_2, playlist_member_id_2_1, &order_4);
1494         media_playlist_get_play_order(playlist_2, playlist_member_id_2_2, &order_5);
1495         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);
1496
1497         /* Update Playlist */
1498         media_playlist_remove_media(playlist_2, playlist_member_id_2_1);
1499         media_playlist_add_media(playlist_2, test_video_id);
1500         media_playlist_set_name(playlist_2, "test_playlist");
1501         media_playlist_set_play_order(playlist_2, playlist_member_id_2_2, order_5+100);
1502         media_playlist_update_to_db(playlist_2);
1503
1504         /* Get Updated Playlist*/
1505         media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, NULL);
1506
1507         /* deletes the playlist */
1508 #if 0
1509         media_playlist_delete_from_db(playlist_id_1);
1510         media_playlist_delete_from_db(playlist_id_2);
1511 #endif
1512
1513         if (playlist_1 != NULL)
1514                 media_playlist_destroy(playlist_1);
1515         if (playlist_2 != NULL)
1516                 media_playlist_destroy(playlist_2);
1517         if (playlist_3 != NULL)
1518                 media_playlist_destroy(playlist_3);
1519         if (playlist_4 != NULL)
1520                 media_playlist_destroy(playlist_4);
1521
1522         g_list_free(playlist_id_list);
1523         g_list_free(playlist_member_id_list);
1524         g_list_free(playlist_member_id_list_1);
1525
1526         if (filter != NULL)
1527                 ret = media_filter_destroy(filter);
1528         if (m_filter != NULL)
1529                 ret = media_filter_destroy(m_filter);
1530
1531         return ret;
1532 }
1533
1534 int test_playlist_operation_v2(void)
1535 {
1536         int ret = MEDIA_CONTENT_ERROR_NONE;
1537         media_playlist_h playlist_1 = NULL;
1538         const char *playlist_name_1 = "myPlaylist_1";
1539         const char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1540         int playlist_id = 0;
1541
1542         content_debug("\n============Playlist Test V2============\n\n");
1543
1544         ret = media_playlist_create(&playlist_1);
1545         if (ret != MEDIA_CONTENT_ERROR_NONE)
1546                 content_error("error media_playlist_create : [%d]", ret);
1547
1548         ret = media_playlist_set_name(playlist_1, playlist_name_1);
1549         if (ret != MEDIA_CONTENT_ERROR_NONE)
1550                 content_error("error media_playlist_set_name : [%d]", ret);
1551
1552         ret = media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path);
1553         if (ret != MEDIA_CONTENT_ERROR_NONE)
1554                 content_error("error media_playlist_set_thumbnail_path : [%d]", ret);
1555
1556         ret = media_playlist_insert_to_db_v2(playlist_1);
1557         if (ret != MEDIA_CONTENT_ERROR_NONE)
1558                 content_error("error media_playlist_insert_to_db_v2 : [%d]", ret);
1559
1560         ret = media_playlist_set_name(playlist_1, "myPlaylist_3");
1561         if (ret != MEDIA_CONTENT_ERROR_NONE)
1562                 content_error("error media_playlist_set_name : [%d]", ret);
1563
1564         ret = media_playlist_get_playlist_id(playlist_1, &playlist_id);
1565         if (ret != MEDIA_CONTENT_ERROR_NONE)
1566                 content_error("error media_playlist_get_playlist_id : [%d]", ret);
1567
1568         ret = media_playlist_update_to_db_v2(playlist_id, playlist_1);
1569         if (ret != MEDIA_CONTENT_ERROR_NONE)
1570                 content_error("error media_playlist_update_to_db_v2 : [%d]", ret);
1571
1572         ret = media_playlist_destroy(playlist_1);
1573         if (ret != MEDIA_CONTENT_ERROR_NONE)
1574                 content_error("error media_playlist_destroy : [%d]", ret);
1575
1576         return ret;
1577 }
1578
1579 int test_tag_operation(void)
1580 {
1581         int ret = MEDIA_CONTENT_ERROR_NONE;
1582         media_tag_h tag_1;
1583         media_tag_h tag_2;
1584         media_tag_h tag_3;
1585         int tag_id_1 = 0;
1586         int tag_id_2 = 0;
1587         int tag_id_3 = 0;
1588         const char *tag_name_1 = "myTag_1";
1589         const char *tag_name_2 = "myTag_2";
1590         const char *tag_name_3 = "myTag_3";
1591         int tag_count = 0;
1592         int media_count = 0;
1593         filter_h filter;
1594
1595         content_debug("\n============Tag Test============\n\n");
1596
1597         const char *g_condition = "TAG_NAME like \"%%my%%\"";
1598
1599         ret = media_filter_create(&filter);
1600
1601         ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1602
1603         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
1604
1605         /* Create Tag */
1606         ret = media_tag_insert_to_db(tag_name_1, &tag_1);
1607         if (ret != MEDIA_CONTENT_ERROR_NONE)
1608                 content_error("error media_tag_insert_to_db : [%d]", ret);
1609         ret = media_tag_insert_to_db(tag_name_2, &tag_2);
1610         if (ret != MEDIA_CONTENT_ERROR_NONE)
1611                 content_error("error media_tag_insert_to_db : [%d]", ret);
1612         ret = media_tag_insert_to_db(tag_name_3, &tag_3);
1613         if (ret != MEDIA_CONTENT_ERROR_NONE)
1614                 content_error("error media_tag_insert_to_db : [%d]", ret);
1615
1616         /* Add media to Tag */
1617         ret = media_tag_add_media(tag_1, test_audio_id);
1618         if (ret != MEDIA_CONTENT_ERROR_NONE)
1619                 content_error("error media_tag_add_media : [%d]", ret);
1620         ret = media_tag_add_media(tag_1, test_video_id);
1621         if (ret != MEDIA_CONTENT_ERROR_NONE)
1622                 content_error("error media_tag_add_media : [%d]", ret);
1623         ret = media_tag_update_to_db(tag_1);
1624         if (ret != MEDIA_CONTENT_ERROR_NONE)
1625                 content_error("error media_tag_update_to_db : [%d]", ret);
1626
1627         ret = media_tag_add_media(tag_2, test_audio_id);
1628         if (ret != MEDIA_CONTENT_ERROR_NONE)
1629                 content_error("error media_tag_add_media : [%d]", ret);
1630         ret = media_tag_update_to_db(tag_2);
1631         if (ret != MEDIA_CONTENT_ERROR_NONE)
1632                 content_error("error media_tag_update_to_db : [%d]", ret);
1633
1634         /* Get Tag Count*/
1635         ret = media_tag_get_tag_count_from_db(filter, &tag_count);
1636         if (ret != MEDIA_CONTENT_ERROR_NONE)
1637                 content_error("error media_tag_get_tag_count_from_db : [%d]", ret);
1638         else
1639                 content_debug("tag_count [%d]", tag_count);
1640
1641         /* Get Tag*/
1642         ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1643         if (ret != MEDIA_CONTENT_ERROR_NONE)
1644                 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1645
1646         /* Get Tag id*/
1647         ret = media_tag_get_tag_id(tag_1, &tag_id_1);
1648         if (ret != MEDIA_CONTENT_ERROR_NONE)
1649                 content_error("error media_tag_get_tag_id : [%d]", ret);
1650         else
1651                 content_debug("tag_id_1 [%d]", tag_id_1);
1652
1653         ret = media_tag_get_tag_id(tag_2, &tag_id_2);
1654         if (ret != MEDIA_CONTENT_ERROR_NONE)
1655                 content_error("error media_tag_get_tag_id : [%d]", ret);
1656         else
1657                 content_debug("tag_id_2 [%d]", tag_id_2);
1658
1659         ret = media_tag_get_tag_id(tag_3, &tag_id_3);
1660         if (ret != MEDIA_CONTENT_ERROR_NONE)
1661                 content_error("error media_tag_get_tag_id : [%d]", ret);
1662         else
1663                 content_debug("tag_id_3 [%d]", tag_id_3);
1664
1665         /* Get media count */
1666         ret = media_tag_get_media_count_from_db(tag_id_1, NULL, &media_count);
1667         if (ret != MEDIA_CONTENT_ERROR_NONE)
1668                 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1669         else
1670                 content_debug("tag_1_media_count [%d]", media_count);
1671
1672         ret = media_tag_get_media_count_from_db(tag_id_2, NULL, &media_count);
1673         if (ret != MEDIA_CONTENT_ERROR_NONE)
1674                 content_error("error media_tag_get_media_count_from_db : [%d]", ret);
1675         else
1676                 content_debug("tag_2_media_count [%d]", media_count);
1677
1678         /* Get media of Tag */
1679         ret = media_tag_foreach_media_from_db(tag_id_1, NULL, media_item_cb, NULL);
1680         if (ret != MEDIA_CONTENT_ERROR_NONE)
1681                 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1682
1683         ret = media_tag_foreach_media_from_db(tag_id_2, NULL, media_item_cb, NULL);
1684         if (ret != MEDIA_CONTENT_ERROR_NONE)
1685                 content_error("error media_tag_foreach_media_from_db : [%d]", ret);
1686
1687         /* Update Tag */
1688         ret = media_tag_add_media(tag_2, test_video_id);
1689         if (ret != MEDIA_CONTENT_ERROR_NONE)
1690                 content_error("error media_tag_add_media : [%d]", ret);
1691         ret = media_tag_set_name(tag_2, "test_tag");
1692         if (ret != MEDIA_CONTENT_ERROR_NONE)
1693                 content_error("error media_tag_set_name : [%d]", ret);
1694         ret = media_tag_update_to_db(tag_2);
1695         if (ret != MEDIA_CONTENT_ERROR_NONE)
1696                 content_error("error media_tag_update_to_db : [%d]", ret);
1697
1698         /* Get Updated Tag*/
1699         ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
1700         if (ret != MEDIA_CONTENT_ERROR_NONE)
1701                 content_error("error media_tag_foreach_tag_from_db : [%d]", ret);
1702
1703         /* deletes the tag */
1704         ret = media_tag_delete_from_db(tag_id_1);
1705         if (ret != MEDIA_CONTENT_ERROR_NONE)
1706                 content_error("error media_tag_delete_from_db : [%d]", ret);
1707         ret = media_tag_delete_from_db(tag_id_2);
1708         if (ret != MEDIA_CONTENT_ERROR_NONE)
1709                 content_error("error media_tag_delete_from_db : [%d]", ret);
1710
1711         ret = media_tag_destroy(tag_1);
1712         if (ret != MEDIA_CONTENT_ERROR_NONE)
1713                 content_error("error media_tag_destroy : [%d]", ret);
1714         ret = media_tag_destroy(tag_2);
1715         if (ret != MEDIA_CONTENT_ERROR_NONE)
1716                 content_error("error media_tag_destroy : [%d]", ret);
1717         ret = media_tag_destroy(tag_3);
1718         if (ret != MEDIA_CONTENT_ERROR_NONE)
1719                 content_error("error media_tag_destroy : [%d]", ret);
1720         ret = media_filter_destroy(filter);
1721         if (ret != MEDIA_CONTENT_ERROR_NONE)
1722                 content_error("error media_filter_destroy : [%d]", ret);
1723
1724         return ret;
1725 }
1726
1727 int test_tag_operation_v2(void)
1728 {
1729         int ret = MEDIA_CONTENT_ERROR_NONE;
1730         media_tag_h tag_1;
1731         const char *tag_name_1 = "myTag_1";
1732         int tag_id = -1;
1733
1734         content_debug("\n============Tag Test V2============\n\n");
1735
1736         /* Create Tag */
1737         ret = media_tag_create(&tag_1);
1738         if (ret != MEDIA_CONTENT_ERROR_NONE)
1739                 content_error("error media_tag_create : [%d]", ret);
1740
1741         ret = media_tag_set_name(tag_1, tag_name_1);
1742         if (ret != MEDIA_CONTENT_ERROR_NONE)
1743                 content_error("error media_tag_set_name : [%d]", ret);
1744
1745         /* Add media to Tag */
1746         ret = media_tag_add_media(tag_1, test_audio_id);
1747         if (ret != MEDIA_CONTENT_ERROR_NONE)
1748                 content_error("error media_tag_add_media : [%d]", ret);
1749
1750         ret = media_tag_add_media(tag_1, test_video_id);
1751         if (ret != MEDIA_CONTENT_ERROR_NONE)
1752                 content_error("error media_tag_add_media : [%d]", ret);
1753
1754         ret = media_tag_insert_to_db_v2(tag_1);
1755         if (ret != MEDIA_CONTENT_ERROR_NONE)
1756                 content_error("error media_tag_insert_to_db_v2 : [%d]", ret);
1757
1758 #if 1
1759         ret = media_tag_get_tag_id(tag_1, &tag_id);
1760         if (ret != MEDIA_CONTENT_ERROR_NONE)
1761                 content_error("error media_tag_get_tag_id : [%d]", ret);
1762
1763         ret = media_tag_remove_media(tag_1, test_video_id);
1764         if (ret != MEDIA_CONTENT_ERROR_NONE)
1765                 content_error("error media_tag_add_media : [%d]", ret);
1766
1767         ret = media_tag_update_to_db_v2(tag_id, tag_1);
1768         if (ret != MEDIA_CONTENT_ERROR_NONE)
1769                 content_error("error media_tag_update_to_db_v2 : [%d]", ret);
1770 #endif
1771
1772         ret = media_tag_destroy(tag_1);
1773         if (ret != MEDIA_CONTENT_ERROR_NONE)
1774                 content_error("error media_tag_destroy : [%d]", ret);
1775
1776         return ret;
1777 }
1778
1779 int test_bookmark_operation(void)
1780 {
1781         /* bookmark is only supported for video information. */
1782         int ret = MEDIA_CONTENT_ERROR_NONE;
1783         int bookmark_count = 0;
1784         filter_h filter;
1785         GList *all_item_list = NULL;
1786         int idx = 0;
1787
1788         content_debug("\n============Bookmark Test============\n\n");
1789
1790         const char *g_condition = "BOOKMARK_MARKED_TIME > 300";
1791
1792         ret = media_filter_create(&filter);
1793         if (ret != MEDIA_CONTENT_ERROR_NONE)
1794                 content_error("error media_filter_create : [%d]", ret);
1795
1796         ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1797         if (ret != MEDIA_CONTENT_ERROR_NONE)
1798                 content_error("error media_filter_set_condition : [%d]", ret);
1799
1800         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, BOOKMARK_MARKED_TIME, MEDIA_CONTENT_COLLATE_DEFAULT);
1801         if (ret != MEDIA_CONTENT_ERROR_NONE)
1802                 content_error("error media_filter_set_order : [%d]", ret);
1803
1804         /* insert bookmark to video */
1805         const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1806         ret = media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1);
1807         if (ret != MEDIA_CONTENT_ERROR_NONE)
1808                 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1809
1810         ret = media_bookmark_insert_to_db(test_video_id, 600, thumbnail_path1);
1811         if (ret != MEDIA_CONTENT_ERROR_NONE)
1812                 content_error("error media_bookmark_insert_to_db : [%d]", ret);
1813
1814         ret = media_bookmark_get_bookmark_count_from_db(filter, &bookmark_count);
1815         if (ret != MEDIA_CONTENT_ERROR_NONE)
1816                 content_error("error media_bookmark_get_bookmark_count_from_db : [%d]", ret);
1817         else
1818                 content_debug("bookmark_count = [%d]", bookmark_count);
1819
1820         ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, &all_item_list);
1821         if (ret != MEDIA_CONTENT_ERROR_NONE)
1822                 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1823
1824         for (idx = 0; idx < g_list_length(all_item_list); idx++) {
1825                 media_bookmark_h bookmark_handle;
1826                 bookmark_handle = (media_bookmark_h)g_list_nth_data(all_item_list, idx);
1827
1828                 ret = media_bookmark_set_name(bookmark_handle, "test 1");
1829                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1830                         content_error("error media_bookmark_set_name : [%d]", ret);
1831
1832                 ret = media_bookmark_update_to_db(bookmark_handle);
1833                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1834                         content_error("error media_bookmark_update_to_db : [%d]", ret);
1835         }
1836
1837         ret = media_info_foreach_bookmark_from_db(test_video_id, NULL, bookmarks_cb, NULL);
1838         if (ret != MEDIA_CONTENT_ERROR_NONE)
1839                 content_error("error media_info_foreach_bookmark_from_db : [%d]", ret);
1840
1841         ret = media_filter_destroy(filter);
1842         if (ret != MEDIA_CONTENT_ERROR_NONE)
1843                 content_error("error media_filter_destroy : [%d]", ret);
1844
1845         return ret;
1846 }
1847
1848 int test_bookmark_operation_v2(void)
1849 {
1850         content_debug("\n============Bookmark Test V2============\n\n");
1851
1852         int ret = MEDIA_CONTENT_ERROR_NONE;
1853         media_bookmark_h bookmark = NULL;
1854         const char *thumbnail_path1 = tzplatform_mkpath(TZ_USER_VIDEOS, "teat11.jpg");
1855
1856         ret = media_bookmark_create(test_video_id, 400, &bookmark);
1857         if (ret != MEDIA_CONTENT_ERROR_NONE)
1858                 content_error("error media_bookmark_create : [%d]", ret);
1859
1860         ret = media_bookmark_set_name(bookmark, "test bookmark");
1861         if (ret != MEDIA_CONTENT_ERROR_NONE)
1862                 content_error("error media_bookmark_set_name : [%d]", ret);
1863
1864         ret = media_bookmark_set_thumbnail_path(bookmark, thumbnail_path1);
1865         if (ret != MEDIA_CONTENT_ERROR_NONE)
1866                 content_error("error media_bookmark_set_thumbnail_path : [%d]", ret);
1867
1868         ret = media_bookmark_insert_to_db_v2(bookmark);
1869         if (ret != MEDIA_CONTENT_ERROR_NONE)
1870                 content_error("error media_bookmark_insert_to_db_v2 : [%d]", ret);
1871
1872         ret = media_bookmark_set_name(bookmark, "test bookmark 2");
1873         if (ret != MEDIA_CONTENT_ERROR_NONE)
1874                 content_error("error media_bookmark_set_name : [%d]", ret);
1875
1876         ret = media_bookmark_update_to_db(bookmark);
1877         if (ret != MEDIA_CONTENT_ERROR_NONE)
1878                 content_error("error media_bookmark_update_to_db : [%d]", ret);
1879
1880         ret = media_bookmark_destroy(bookmark);
1881         if (ret != MEDIA_CONTENT_ERROR_NONE)
1882                 content_error("error media_bookmark_destroy : [%d]", ret);
1883
1884         return ret;
1885 }
1886
1887 int test_album_list(void)
1888 {
1889         content_debug("\n============Album Test============\n\n");
1890
1891         int ret = MEDIA_CONTENT_ERROR_NONE;
1892         int album_count = 0;
1893         filter_h filter;
1894
1895         /*Set Filter*/
1896         const char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
1897
1898         ret = media_filter_create(&filter);
1899         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1900                 content_error("Fail to create filter");
1901                 return ret;
1902         }
1903         ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
1904         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1905                 media_filter_destroy(filter);
1906                 content_error("Fail to set condition");
1907                 return ret;
1908         }
1909         ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
1910         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1911                 media_filter_destroy(filter);
1912                 content_error("Fail to set order");
1913                 return ret;
1914         }
1915
1916         ret = media_album_get_album_count_from_db(filter, &album_count);
1917         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1918                 media_filter_destroy(filter);
1919                 return ret;
1920         } else {
1921                 content_debug("album_count [%d]", album_count);
1922         }
1923
1924         ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
1925         if (ret != MEDIA_CONTENT_ERROR_NONE)
1926                 content_error("error media_album_foreach_album_from_db : [%d]", ret);
1927
1928         ret = media_filter_destroy(filter);
1929         if (ret != MEDIA_CONTENT_ERROR_NONE)
1930                 content_error("error media_filter_destroy : [%d]", ret);
1931
1932         return ret;
1933 }
1934
1935 int test_group_operation(void)
1936 {
1937         content_debug("\n============Group Test============\n\n");
1938
1939         int ret = MEDIA_CONTENT_ERROR_NONE;
1940         int group_count = 0;
1941         int idx = 0;
1942
1943         ret = test_filter_create();
1944         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1945                 content_error("[error(0x%08x)", ret);
1946                 return ret;
1947         }
1948
1949         for (idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) {
1950                 ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
1951                 if (ret != MEDIA_CONTENT_ERROR_NONE) {
1952                         test_filter_destroy();
1953                         content_error("media_group_get_group_count_from_db fail. ret=[%d] idx=[%d]", ret, idx);
1954                         return ret;
1955                 } else {
1956                         content_debug("[%2d]group_count [%d]", idx, group_count);
1957                 }
1958
1959                 ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
1960                 if (ret != MEDIA_CONTENT_ERROR_NONE)
1961                         content_error("media_group_foreach_group_from_db failed: %d", ret);
1962         }
1963         ret = test_filter_destroy();
1964
1965         return ret;
1966 }
1967
1968 int test_update_operation()
1969 {
1970         int ret = MEDIA_CONTENT_ERROR_NONE;
1971         unsigned int i = 0;
1972         media_info_h media_handle = NULL;
1973         GList *all_item_list = NULL;
1974
1975         /* Get all item list */
1976         ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
1977         if (ret != MEDIA_CONTENT_ERROR_NONE) {
1978                 content_error("media_info_foreach_media_from_db failed: %d", ret);
1979                 return -1;
1980         } else {
1981                 content_debug("media_info_foreach_media_from_db success");
1982
1983                 for (i = 0; i < g_list_length(all_item_list); i++) {
1984                         media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
1985                         get_media_meta(media_handle);
1986                 }
1987         }
1988
1989         return MEDIA_CONTENT_ERROR_NONE;
1990 }
1991
1992 int test_insert(void)
1993 {
1994         int ret = MEDIA_CONTENT_ERROR_NONE;
1995         const char *path = tzplatform_mkpath(TZ_USER_IMAGES, "Default.jpg");
1996 #if 0
1997         const char *path = tzplatform_mkpath(TZ_USER_DOCUMENTS, "other.txt"));
1998         char *path = NULL;
1999 #endif
2000         media_info_h media_item = NULL;
2001         content_debug("\n============DB Insert Test============\n\n");
2002
2003         ret = media_info_insert_to_db(path, &media_item);
2004
2005         if ((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) {
2006                 content_debug("Insertion is success");
2007         } else {
2008                 content_error("Insertion is failed");
2009                 ret = media_info_destroy(media_item);
2010                 return ret;
2011         }
2012
2013         char *media_id = NULL;
2014
2015         ret = media_info_get_media_id(media_item, &media_id);
2016         if (ret != MEDIA_CONTENT_ERROR_NONE)
2017                 content_error("media_info_get_media_id failed: %d", ret);
2018         else
2019                 content_debug("Media ID: %s", media_id);
2020
2021         SAFE_FREE(media_id);
2022
2023         ret = media_info_update_to_db(media_item);
2024         if (ret == MEDIA_CONTENT_ERROR_NONE)
2025                 content_debug("media_info_update_to_db is success");
2026         else
2027                 content_error("media_info_update_to_db is failed");
2028
2029         ret = media_info_destroy(media_item);
2030         if (ret != MEDIA_CONTENT_ERROR_NONE)
2031                 content_error("media_info_destroy failed: %d", ret);
2032
2033         return ret;
2034 }
2035
2036 int test_move(void)
2037 {
2038         int ret = MEDIA_CONTENT_ERROR_NONE;
2039         const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
2040         const char *dst_path = tzplatform_mkpath(TZ_USER_IMAGES, "XX/Default1.jpg");
2041         media_info_h move_media = NULL;
2042
2043         ret = media_info_get_media_from_db(move_media_id, &move_media);
2044         if (ret == MEDIA_CONTENT_ERROR_NONE)
2045                 content_debug("media_info_get_media_from_db success");
2046         else
2047                 content_error("media_info_get_media_from_db failed: %d", ret);
2048
2049         content_debug("\n============DB Move Test============\n\n");
2050
2051         if (move_media) {
2052                 ret = media_info_move_to_db(move_media, dst_path);
2053
2054                 if (ret == MEDIA_CONTENT_ERROR_NONE)
2055                         content_debug("Move is success");
2056                 else
2057                         content_error("Move is failed");
2058
2059                 ret = media_info_destroy(move_media);
2060         } else {
2061                 content_debug("There is no item : %s", move_media_id);
2062         }
2063
2064         return ret;
2065 }
2066
2067 void thumbnail_completed_cb(media_content_error_e error, const char *path, void *user_data)
2068 {
2069         char *thumbnail_path = NULL;
2070         int ret = MEDIA_CONTENT_ERROR_NONE;
2071         g_cnt++;
2072
2073         content_debug("=================[%d][%d]", g_media_cnt, g_cnt);
2074         content_debug("error_code [%d]", error);
2075         content_debug("thumbnail_path [%s]", path);
2076         if (user_data != NULL) {
2077                 media_info_h media = (media_info_h)user_data;
2078                 ret = media_info_get_thumbnail_path(media, &thumbnail_path);
2079                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2080                         content_error("media_info_get_thumbnail_path failed: %d", ret);
2081                 else
2082                         content_debug("thumbnail_path get from media[%s]", thumbnail_path);
2083                 SAFE_FREE(thumbnail_path);
2084                 ret = media_info_destroy(media);
2085                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2086                         content_error("media_info_destroy failed: %d", ret);
2087         }
2088
2089         if (g_cnt == g_media_cnt)
2090                 g_main_loop_quit(g_loop);
2091
2092         return;
2093 }
2094
2095 bool thumbnail_create_cb(media_info_h media, void *user_data)
2096 {
2097         char *media_id = NULL;
2098         media_info_h dst = NULL;
2099         int ret = MEDIA_CONTENT_ERROR_NONE;
2100
2101         if (media == NULL) {
2102                 content_debug("NO Item");
2103                 return true;
2104         }
2105
2106         ret = media_info_get_media_id(media, &media_id);
2107         if (ret != MEDIA_CONTENT_ERROR_NONE)
2108                 content_error("media_info_get_media_id failed: %d", ret);
2109         else
2110                 content_debug("media_id : [%s]", media_id);
2111
2112         ret = media_info_clone(&dst, media);
2113         if (ret != MEDIA_CONTENT_ERROR_NONE)
2114                 content_error("media_info_clone failed: %d", ret);
2115         else {
2116                 ret = media_info_create_thumbnail(dst, thumbnail_completed_cb, dst);
2117                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2118                         content_error("media_info_create_thumbnail failed: %d", ret);
2119         }
2120
2121         /* fix prevent: Resource leak */
2122         SAFE_FREE(media_id);
2123
2124         return true;
2125 }
2126
2127 bool thumbnail_cancel_cb(media_info_h media, void *user_data)
2128 {
2129         int ret = MEDIA_CONTENT_ERROR_NONE;
2130
2131         char *media_id = NULL;
2132         media_info_h dst = NULL;
2133
2134         g_cnt++;
2135
2136         if (media == NULL) {
2137                 content_debug("NO Item");
2138                 return true;
2139         }
2140
2141         ret = media_info_get_media_id(media, &media_id);
2142         if (ret != MEDIA_CONTENT_ERROR_NONE)
2143                 content_error("media_info_get_media_id failed: %d", ret);
2144         else
2145                 content_debug("media_id : [%s]", media_id);
2146
2147         ret = media_info_clone(&dst, media);
2148         if (ret != MEDIA_CONTENT_ERROR_NONE)
2149                 content_error("media_info_clone failed: %d", ret);
2150
2151         ret = media_info_cancel_thumbnail(dst);
2152         if (ret != MEDIA_CONTENT_ERROR_NONE)
2153                 content_error("media_info_cancel_thumbnail failed: %d", ret);
2154
2155         ret = media_info_destroy(dst);
2156         if (ret != MEDIA_CONTENT_ERROR_NONE)
2157                         content_error("media_info_destroy failed: %d", ret);
2158
2159         if (g_cnt == g_media_cnt)
2160                 g_main_loop_quit(g_loop);
2161
2162         /* fix prevent: Resource leak */
2163         SAFE_FREE(media_id);
2164
2165         return true;
2166 }
2167
2168 gboolean create_thumbnail_start(gpointer data)
2169 {
2170         int ret = MEDIA_CONTENT_ERROR_NONE;
2171
2172         ret = media_info_foreach_media_from_db(g_filter, thumbnail_create_cb, NULL);
2173
2174         if (ret == MEDIA_CONTENT_ERROR_NONE)
2175                 content_debug("media_info_foreach_media_from_db is success");
2176         else
2177                 content_error("media_info_foreach_media_from_db is failed");
2178
2179         return false;
2180 }
2181
2182 gboolean cancel_thumbnail_start(gpointer data)
2183 {
2184         int ret = MEDIA_CONTENT_ERROR_NONE;
2185
2186         ret = media_info_foreach_media_from_db(g_filter, thumbnail_cancel_cb, NULL);
2187
2188         if (ret == MEDIA_CONTENT_ERROR_NONE)
2189                 content_debug("media_info_foreach_media_from_db is success");
2190         else
2191                 content_error("media_info_foreach_media_from_db is failed");
2192
2193         return false;
2194 }
2195
2196 int test_create_thumbnail(int cancel)
2197 {
2198         int ret = MEDIA_CONTENT_ERROR_NONE;
2199         GSource *source = NULL;
2200         GMainContext *context = NULL;
2201
2202         test_filter_create();
2203
2204         ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt);
2205         if (ret != MEDIA_CONTENT_ERROR_NONE)
2206                 content_error("media_info_get_media_count_from_db failed: %d", ret);
2207         else
2208                 content_debug("media_count : [%d]", g_media_cnt);
2209
2210         g_loop = g_main_loop_new(NULL, FALSE);
2211         context = g_main_loop_get_context(g_loop);
2212         source = g_idle_source_new();
2213         g_source_set_callback(source, create_thumbnail_start, NULL, NULL);
2214         g_source_attach(source, context);
2215
2216         /* Logic to cancel */
2217         if (cancel) {
2218                 GSource *cancel_src = NULL;
2219                 cancel_src = g_idle_source_new();
2220                 g_source_set_callback(cancel_src, cancel_thumbnail_start, NULL, NULL);
2221                 g_source_attach(cancel_src, context);
2222         }
2223
2224         g_main_loop_run(g_loop);
2225         g_main_loop_unref(g_loop);
2226
2227         test_filter_destroy();
2228
2229         return ret;
2230 }
2231
2232 bool face_cb(media_face_h face, void *user_data)
2233 {
2234         get_face_meta(face);
2235
2236         return false;
2237 }
2238
2239 void face_detection_complete_cb(media_content_error_e error, int count, void *user_data)
2240 {
2241         int ret = MEDIA_CONTENT_ERROR_NONE;
2242         g_cnt++;
2243
2244         content_debug("=================[%d][%d]", g_media_cnt, g_cnt);
2245         content_debug("error_code [%d]", error);
2246         content_debug("face_count [%d]", count);
2247         if (count == 0) {
2248                 content_debug("No faces are detected!");
2249         } else if (user_data != NULL) {
2250                 media_info_h media = (media_info_h)user_data;
2251                 char *media_id = NULL;
2252                 ret = media_info_get_media_id(media, &media_id);
2253                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2254                         content_error("media_info_get_media_id failed: %d", ret);
2255                 if (media_id != NULL) {
2256                         ret = media_info_foreach_face_from_db(media_id, NULL, face_cb, NULL);
2257                         SAFE_FREE(media_id);
2258                         if (ret != MEDIA_CONTENT_ERROR_NONE)
2259                                 content_error("media_info_foreach_face_from_db failed: %d", ret);
2260                 }
2261                 ret = media_info_destroy(media);
2262                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2263                         content_error("media_info_destroy failed: %d", ret);
2264         }
2265
2266         if (g_cnt == g_media_cnt)
2267                 g_main_loop_quit(g_loop);
2268
2269         return;
2270 }
2271
2272 bool start_face_detection_cb(media_info_h media, void *user_data)
2273 {
2274         char *media_id = NULL;
2275         media_info_h dst = NULL;
2276         int ret = MEDIA_CONTENT_ERROR_NONE;
2277
2278         if (media == NULL) {
2279                 content_debug("NO Item");
2280                 return true;
2281         }
2282
2283         ret = media_info_get_media_id(media, &media_id);
2284         if (ret != MEDIA_CONTENT_ERROR_NONE)
2285                 content_error("media_info_get_media_id failed: %d", ret);
2286         else
2287                 content_debug("media_id : [%s]", media_id);
2288
2289         ret = media_info_clone(&dst, media);
2290         if (ret != MEDIA_CONTENT_ERROR_NONE)
2291                 content_error("media_info_clone failed: %d", ret);
2292
2293         GList **list = (GList**)user_data;
2294         *list = g_list_append(*list, dst);
2295
2296         /* fix prevent: Resource leak */
2297         SAFE_FREE(media_id);
2298
2299         return true;
2300 }
2301
2302 bool cancel_face_detection_cb(media_info_h media, void *user_data)
2303 {
2304         int ret = MEDIA_CONTENT_ERROR_NONE;
2305
2306         char *media_id = NULL;
2307         media_info_h dst = NULL;
2308
2309         g_cnt++;
2310
2311         if (media == NULL) {
2312                 content_debug("NO Item");
2313                 return true;
2314         }
2315
2316         ret = media_info_get_media_id(media, &media_id);
2317         if (ret != MEDIA_CONTENT_ERROR_NONE)
2318                 content_error("media_info_get_media_id failed: %d", ret);
2319         else
2320                 content_debug("media_id : [%s]", media_id);
2321
2322         ret = media_info_clone(&dst, media);
2323         if (ret != MEDIA_CONTENT_ERROR_NONE)
2324                 content_error("media_info_clone failed: %d", ret);
2325
2326         ret = media_info_cancel_face_detection(dst);
2327         if (ret != MEDIA_CONTENT_ERROR_NONE)
2328                 content_error("media_info_cancel_face_detection failed: %d", ret);
2329
2330         ret = media_info_destroy(dst);
2331         if (ret != MEDIA_CONTENT_ERROR_NONE)
2332                         content_error("media_info_destroy failed: %d", ret);
2333
2334         if (g_cnt == g_media_cnt)
2335                 g_main_loop_quit(g_loop);
2336
2337         /* fix prevent: Resource leak */
2338         SAFE_FREE(media_id);
2339
2340         return true;
2341 }
2342
2343 gboolean face_detection_start(gpointer data)
2344 {
2345         int ret = MEDIA_CONTENT_ERROR_NONE;
2346         GList *all_item_list = NULL;
2347         int idx = 0;
2348
2349         ret = media_info_foreach_media_from_db(g_filter, start_face_detection_cb, &all_item_list);
2350
2351         if (ret == MEDIA_CONTENT_ERROR_NONE)
2352                 content_debug("media_info_foreach_media_from_db is success");
2353         else
2354                 content_error("media_info_foreach_media_from_db is failed");
2355
2356         for (idx = 0; idx < g_list_length(all_item_list); idx++) {
2357                 media_info_h media_handle = NULL;
2358
2359                 media_handle = (media_info_h)g_list_nth_data(all_item_list, idx);
2360
2361                 ret = media_info_start_face_detection(media_handle, face_detection_complete_cb, NULL);
2362                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2363                         content_error("media_info_start_face_detection failed: %d", ret);
2364
2365         }
2366
2367         return false;
2368 }
2369
2370 gboolean face_detection_cancel(gpointer data)
2371 {
2372         int ret = MEDIA_CONTENT_ERROR_NONE;
2373
2374         ret = media_info_foreach_media_from_db(g_filter, cancel_face_detection_cb, NULL);
2375
2376         if (ret == MEDIA_CONTENT_ERROR_NONE)
2377                 content_debug("media_info_foreach_media_from_db is success");
2378         else
2379                 content_error("media_info_foreach_media_from_db is failed");
2380
2381         return false;
2382 }
2383
2384 int test_start_face_detection(int cancel)
2385 {
2386         int ret = MEDIA_CONTENT_ERROR_NONE;
2387         GSource *source = NULL;
2388         GMainContext *context = NULL;
2389
2390         test_filter_create();
2391
2392         ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt);
2393         if (ret != MEDIA_CONTENT_ERROR_NONE)
2394                 content_error("media_info_get_media_count_from_db failed: %d", ret);
2395         else
2396                 content_debug("media_count : [%d]", g_media_cnt);
2397
2398         if (g_media_cnt == 0)
2399                 goto END;
2400
2401         g_loop = g_main_loop_new(NULL, FALSE);
2402         context = g_main_loop_get_context(g_loop);
2403         source = g_idle_source_new();
2404         g_source_set_callback(source, face_detection_start, NULL, NULL);
2405         g_source_attach(source, context);
2406
2407         /* Logic to cancel */
2408         if (cancel) {
2409                 GSource *cancel_src = NULL;
2410                 cancel_src = g_idle_source_new();
2411                 g_source_set_callback(cancel_src, face_detection_cancel, NULL, NULL);
2412                 g_source_attach(cancel_src, context);
2413         }
2414
2415         g_main_loop_run(g_loop);
2416         g_main_loop_unref(g_loop);
2417
2418 END:
2419         test_filter_destroy();
2420
2421         return ret;
2422 }
2423
2424 int test_ebook_text_finder(const char *keyword)
2425 {
2426         int ret = MEDIA_CONTENT_ERROR_NONE;
2427         char **book_path_list = NULL;
2428         unsigned int book_path_len = 0;
2429         unsigned int i = 0;
2430         media_info_h media = NULL;
2431         book_meta_h book = NULL;
2432         char *s_value = NULL;
2433         long long ms_time = 0;
2434         struct timeval start_time;
2435         struct timeval end_time;
2436
2437         gettimeofday(&start_time, NULL);
2438
2439         ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
2440         if (ret == MEDIA_CONTENT_ERROR_NONE)
2441                 content_debug("book_meta_get_path_with_keyword is success");
2442         else
2443                 content_error("book_meta_get_path_with_keyword is failed");
2444
2445         gettimeofday(&end_time, NULL);
2446
2447         for (i = 0; i < book_path_len; i++) {
2448                 content_debug("=========================== [%d]", i);
2449                 content_debug("%s", book_path_list[i]);
2450                 content_debug("===============================");
2451                 media_info_get_media_from_db_by_path(book_path_list[i], &media);
2452                 media_info_get_title(media, &s_value);
2453                 content_debug("Title  : %s", s_value);
2454                 g_free(s_value);
2455                 media_info_get_book(media, &book);
2456                 book_meta_get_author(book, &s_value);
2457                 content_debug("Author : %s", s_value);
2458                 g_free(s_value);
2459                 book_meta_get_date(book, &s_value);
2460                 content_debug("Date   : %s", s_value);
2461                 g_free(s_value);
2462                 book_meta_destroy(book);
2463                 media_info_destroy(media);
2464                 content_debug("===============================");
2465                 g_free(book_path_list[i]);
2466         }
2467
2468         ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
2469         content_debug("Search Time [%lld]", ms_time);
2470
2471         g_free(book_path_list);
2472
2473         return ret;
2474 }
2475 int test_disconnect_database(void)
2476 {
2477         int ret = MEDIA_CONTENT_ERROR_NONE;
2478         content_debug("\n============DB Disconnection Test============\n\n");
2479
2480         ret = media_content_disconnect();
2481
2482         if (ret == MEDIA_CONTENT_ERROR_NONE)
2483                 content_debug("disconnection is success");
2484         else
2485                 content_error("disconnection is failed");
2486
2487         return ret;
2488 }
2489
2490 int test_request_update_db(void)
2491 {
2492         int ret = MEDIA_CONTENT_ERROR_NONE;
2493         media_info_h media = NULL;
2494         bool favorite = FALSE;
2495
2496         ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2497         if (ret != MEDIA_CONTENT_ERROR_NONE)
2498                 content_error("media_info_get_media_from_db failed: %d", ret);
2499
2500         ret = media_info_set_favorite(media, TRUE);
2501         if (ret != MEDIA_CONTENT_ERROR_NONE)
2502                 content_error("media_info_set_favorite failed: %d", ret);
2503
2504         ret = media_info_update_to_db(media);
2505         if (ret == MEDIA_CONTENT_ERROR_NONE)
2506                 content_debug("media_info_update_to_db is success");
2507         else
2508                 content_error("media_info_update_to_db is failed");
2509
2510         if (media != NULL)
2511                 media_info_destroy(media);
2512
2513         /*get the updated value*/
2514         ret = media_info_get_media_from_db("71b19196-5b38-4ab1-ab34-bfe05c369614", &media);
2515         if (ret != MEDIA_CONTENT_ERROR_NONE)
2516                 content_error("media_info_get_media_from_db failed: %d", ret);
2517
2518         ret = media_info_get_favorite(media, &favorite);
2519         if (ret != MEDIA_CONTENT_ERROR_NONE)
2520                 content_error("media_info_get_favorite failed: %d", ret);
2521         else
2522                 content_debug("favorite [%d]", favorite);
2523
2524         ret = media_info_destroy(media);
2525
2526         return ret;
2527 }
2528
2529 int g_total_photo_size = 0;
2530 int g_total_video_size = 0;
2531 int g_total_mp3_size = 0;
2532 int g_total_voice_memo_size = 0;
2533
2534 bool dft_cb(media_info_h media, void *user_data)
2535 {
2536         unsigned long long file_size = 0;
2537         media_content_type_e media_type = -1;
2538         char *mime_type = NULL;
2539         int ret = MEDIA_CONTENT_ERROR_NONE;
2540
2541         if (media == NULL)
2542                 return true;
2543
2544         ret = media_info_get_media_type(media, &media_type);
2545         if (ret != MEDIA_CONTENT_ERROR_NONE)
2546                 content_error("media_info_get_media_type failed: %d", ret);
2547         ret = media_info_get_size(media, &file_size);
2548         if (ret != MEDIA_CONTENT_ERROR_NONE)
2549                 content_error("media_info_get_size failed: %d", ret);
2550         ret = media_info_get_mime_type(media, &mime_type);
2551         if (ret != MEDIA_CONTENT_ERROR_NONE)
2552                 content_error("media_info_get_mime_type failed: %d", ret);
2553
2554         if (media_type == MEDIA_CONTENT_TYPE_IMAGE)
2555                 g_total_photo_size += file_size;
2556         else if (media_type == MEDIA_CONTENT_TYPE_VIDEO)
2557                 g_total_video_size += file_size;
2558         else if (media_type == MEDIA_CONTENT_TYPE_SOUND)
2559                 g_total_voice_memo_size += file_size;
2560         else if (media_type == MEDIA_CONTENT_TYPE_MUSIC) {
2561                 if ((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
2562                         g_total_mp3_size += file_size;
2563                 else
2564                         g_total_voice_memo_size += file_size;
2565         } else
2566                 content_debug("invalid media_type");
2567
2568         SAFE_FREE(mime_type);
2569
2570         return true;
2571
2572 }
2573
2574 int DFT_test(void)
2575 {
2576         int ret = MEDIA_CONTENT_ERROR_NONE;
2577         content_debug("\n============DFT_test============\n\n");
2578
2579         filter_h filter = NULL;
2580         int media_cnt = 0;
2581
2582         /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
2583
2584         ret = media_filter_create(&filter);
2585
2586 /*Internal Memory*/
2587         content_debug("[Internal Memory]\n");
2588         /*1. Photo ============================================================*/
2589         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2590
2591         /*Get Photo Count*/
2592         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2593         content_debug("Photo count = [%d]\n", media_cnt);
2594
2595         /*Get Photo Size*/
2596         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2597         content_debug("Photo size = [%d]\n", g_total_photo_size);
2598
2599         /*2. Video ============================================================*/
2600         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2601
2602         /*Get Video Count*/
2603         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2604         content_debug("Video count = [%d]\n", media_cnt);
2605
2606         /*Get Video Size*/
2607         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2608         content_debug("Video size = [%d]\n", g_total_video_size);
2609
2610         /*3. MP3 ============================================================*/
2611         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2612
2613         /*Get MP3 Count*/
2614         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2615         content_debug("MP3 count = [%d]\n", media_cnt);
2616
2617         /*Get MP3 Size*/
2618         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2619         content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2620
2621         /*4. Voice Memo ============================================================*/
2622         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);
2623
2624         /*Get Voice Memo Count*/
2625         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2626         content_debug("Voice Memo count = [%d]\n", media_cnt);
2627
2628         /*Get Voice Memo Size*/
2629         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2630         content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2631
2632         g_total_photo_size = 0;
2633         g_total_video_size = 0;
2634         g_total_mp3_size = 0;
2635         g_total_voice_memo_size = 0;
2636
2637 /*External Memory*/
2638         content_debug("\n[External Memory]\n");
2639         /*1. Photo ============================================================*/
2640         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
2641
2642         /*Get Photo Count*/
2643         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2644         content_debug("Photo count = [%d]\n", media_cnt);
2645
2646         /*Get Photo Size*/
2647         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2648         content_debug("Photo size = [%d]\n", g_total_photo_size);
2649
2650         /*2. Video ============================================================*/
2651         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
2652
2653         /*Get Video Count*/
2654         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2655         content_debug("Video count = [%d]\n", media_cnt);
2656
2657         /*Get Video Size*/
2658         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2659         content_debug("Video size = [%d]\n", g_total_video_size);
2660
2661         /*3. MP3 ============================================================*/
2662         ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
2663
2664         /*Get MP3 Count*/
2665         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2666         content_debug("MP3 count = [%d]\n", media_cnt);
2667
2668         /*Get MP3 Size*/
2669         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2670         content_debug("MP3 size = [%d]\n", g_total_mp3_size);
2671
2672         /*4. Voice Memo ============================================================*/
2673         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);
2674
2675         /*Get Voice Memo Count*/
2676         ret = media_info_get_media_count_from_db(filter, &media_cnt);
2677         content_debug("Voice Memo count = [%d]\n", media_cnt);
2678
2679         /*Get Voice Memo Size*/
2680         ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
2681         content_debug("Voice Memo size = [%d]\n", g_total_voice_memo_size);
2682         ret = media_filter_destroy(filter);
2683
2684         return ret;
2685 }
2686
2687 void insert_batch_cb(media_content_error_e error, void * user_data)
2688 {
2689         content_debug("media_info_insert_batch_to_db completed!\n");
2690 }
2691
2692 int test_batch_operations()
2693 {
2694         int ret = -1;
2695         int i = 0;
2696         char *file_list[10];
2697
2698         for (i = 0; i < 10; i++) {
2699                 file_list[i] = g_strdup_printf("%s%d.jpg", tzplatform_mkpath(TZ_USER_CONTENT, "test/image"), i+1);
2700                 content_debug("File : %s\n", file_list[i]);
2701         }
2702
2703         ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL);
2704         if (ret != MEDIA_CONTENT_ERROR_NONE)
2705                 content_error("media_info_insert_batch_to_db failed : %d\n", ret);
2706
2707         for (i = 0; i < 10; i++)
2708                 g_free(file_list[i]);
2709
2710         return ret;
2711 }
2712
2713 void _scan_cb(media_content_error_e err, void *user_data)
2714 {
2715         content_debug("scan callback is called : %d\n", err);
2716         g_main_loop_quit(g_loop);
2717
2718         return;
2719 }
2720
2721 int test_scan_file()
2722 {
2723         int ret = -1;
2724
2725         const char *file_path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2726         ret = media_content_scan_file(file_path);
2727         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2728                 content_error("Fail to media_content_scan_file : %d", ret);
2729                 return ret;
2730         }
2731
2732         return 0;
2733 }
2734
2735 gboolean test_scan_dir_start(gpointer data)
2736 {
2737         int ret = -1;
2738
2739         const char *dir_path = tzplatform_getenv(TZ_USER_CONTENT);
2740
2741         ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL);
2742
2743         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2744                 content_error("Fail to test_scan_dir_start : %d", ret);
2745                 return ret;
2746         }
2747
2748         return 0;
2749 }
2750
2751 gboolean cancel_scan_dir_start(gpointer data)
2752 {
2753         int ret = MEDIA_CONTENT_ERROR_NONE;
2754
2755         const char *dir_path = tzplatform_getenv(TZ_USER_IMAGES);
2756
2757         ret = media_content_cancel_scan_folder(dir_path);
2758
2759         if (ret == MEDIA_CONTENT_ERROR_NONE)
2760                 content_debug("media_content_cancel_scan_folder is success");
2761         else
2762                 content_error("media_content_cancel_scan_folder is failed");
2763
2764         return false;
2765 }
2766
2767 int test_scan_dir(int cancel)
2768 {
2769         GSource *source = NULL;
2770         GMainContext *context = NULL;
2771
2772         g_loop = g_main_loop_new(NULL, FALSE);
2773         context = g_main_loop_get_context(g_loop);
2774         source = g_idle_source_new();
2775         g_source_set_callback(source, test_scan_dir_start, NULL, NULL);
2776         g_source_attach(source, context);
2777
2778         if (cancel) {
2779                 GSource *cancel_src = NULL;
2780                 cancel_src = g_idle_source_new();
2781                 g_source_set_callback(cancel_src, cancel_scan_dir_start, NULL, NULL);
2782                 g_source_attach(cancel_src, context);
2783         }
2784
2785         g_main_loop_run(g_loop);
2786         g_main_loop_unref(g_loop);
2787
2788         return 0;
2789 }
2790
2791 void _noti_cb(media_content_error_e error,
2792                                 int pid,
2793                                 media_content_db_update_item_type_e update_item,
2794                                 media_content_db_update_type_e update_type,
2795                                 media_content_type_e media_type,
2796                                 char *uuid,
2797                                 char *path,
2798                                 char *mime_type,
2799                                 void *user_data)
2800 {
2801         if (error == 0)
2802                 content_debug("noti success! : %d\n", error);
2803         else
2804                 content_debug("error occurred! : %d\n", error);
2805
2806         content_debug("Noti from PID(%d)\n", pid);
2807
2808         if (update_item == MEDIA_ITEM_FILE)
2809                 content_debug("Noti item : MEDIA_ITEM_FILE\n");
2810         else if (update_item == MEDIA_ITEM_DIRECTORY)
2811                 content_debug("Noti item : MEDIA_ITEM_DIRECTORY\n");
2812
2813         if (update_type == MEDIA_CONTENT_INSERT)
2814                 content_debug("Noti type : MEDIA_CONTENT_INSERT\n");
2815         else if (update_type == MEDIA_CONTENT_DELETE)
2816                 content_debug("Noti type : MEDIA_CONTENT_DELETE\n");
2817         else if (update_type == MEDIA_CONTENT_UPDATE)
2818                 content_debug("Noti type : MEDIA_CONTENT_UPDATE\n");
2819
2820         content_debug("content type : %d\n", media_type);
2821
2822         if (path)
2823                 content_debug("path : %s\n", path);
2824         else
2825                 content_debug("path not\n");
2826
2827         if (uuid)
2828                 content_debug("uuid : %s\n", uuid);
2829         else
2830                 content_debug("uuid not\n");
2831
2832         if (mime_type)
2833                 content_debug("mime_type : %s\n", mime_type);
2834         else
2835                 content_debug("mime not\n");
2836
2837         if (user_data) content_debug("String : %s\n", (char *)user_data);
2838
2839         return;
2840 }
2841
2842 void _noti_cb_2(media_content_error_e error,
2843                                 int pid,
2844                                 media_content_db_update_item_type_e update_item,
2845                                 media_content_db_update_type_e update_type,
2846                                 media_content_type_e media_type,
2847                                 char *uuid,
2848                                 char *path,
2849                                 char *mime_type,
2850                                 void *user_data)
2851 {
2852         if (error == 0)
2853                 content_debug("noti_2 success! : %d\n", error);
2854         else
2855                 content_debug("error occurred! : %d\n", error);
2856
2857         content_debug("Noti_2 from PID(%d)\n", pid);
2858
2859         g_main_loop_quit(g_loop);
2860         return;
2861 }
2862
2863 static media_content_noti_h noti_h;
2864 static media_content_noti_h noti_h_2;
2865
2866 gboolean _send_noti_operations(gpointer data)
2867 {
2868         int ret = MEDIA_CONTENT_ERROR_NONE;
2869
2870         /* First of all, noti subscription */
2871         char *user_str = strdup("hi");
2872         media_content_add_db_updated_cb(_noti_cb, (void*)user_str, &noti_h);
2873         media_content_add_db_updated_cb(_noti_cb_2, (void*)user_str, &noti_h_2);
2874
2875         /* media_info_insert_to_db */
2876         media_info_h media_item = NULL;
2877         const char *path = tzplatform_mkpath(TZ_USER_CONTENT, "test/image1.jpg");
2878
2879         ret = media_info_insert_to_db(path, &media_item);
2880         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2881                 content_error("media_info_insert_to_db failed : %d", ret);
2882                 media_info_destroy(media_item);
2883                 return FALSE;
2884         }
2885
2886         content_debug("media_info_insert_to_db success");
2887
2888         media_content_remove_db_updated_cb(noti_h);
2889
2890         /* media_info_update_to_db */
2891         ret = media_info_update_to_db(media_item);
2892         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2893                 content_error("media_info_update_to_db failed : %d\n", ret);
2894                 media_info_destroy(media_item);
2895                 return ret;
2896         }
2897
2898         media_info_destroy(media_item);
2899
2900         return FALSE;
2901 }
2902
2903 int test_noti()
2904 {
2905         int ret = MEDIA_CONTENT_ERROR_NONE;
2906         GSource *source = NULL;
2907         GMainContext *context = NULL;
2908
2909         g_loop = g_main_loop_new(NULL, FALSE);
2910         context = g_main_loop_get_context(g_loop);
2911         source = g_idle_source_new();
2912         g_source_set_callback(source, _send_noti_operations, NULL, NULL);
2913         g_source_attach(source, context);
2914
2915         g_main_loop_run(g_loop);
2916         g_main_loop_unref(g_loop);
2917
2918         test_filter_destroy();
2919         media_content_remove_db_updated_cb(noti_h_2);
2920
2921         return ret;
2922 }
2923
2924 bool media_face_test_cb(media_face_h face, void *user_data)
2925 {
2926         get_face_meta(face);
2927
2928         if (user_data != NULL) {
2929                 media_face_h new_face = NULL;
2930                 media_face_clone(&new_face, face);
2931
2932                 GList **list = (GList**)user_data;
2933                 *list = g_list_append(*list, new_face);
2934         }
2935
2936         return true;
2937 }
2938
2939 int test_face(void)
2940 {
2941         int ret = MEDIA_CONTENT_ERROR_NONE;
2942         filter_h filter = NULL;
2943         GList *all_item_list = NULL;
2944         int i = 0;
2945
2946         ret = media_filter_create(&filter);
2947         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
2948
2949         ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", MEDIA_CONTENT_COLLATE_DEFAULT);
2950         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2951                 media_filter_destroy(filter);
2952                 content_error("Fail to set condition");
2953                 return ret;
2954         }
2955
2956         ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
2957         if (ret != MEDIA_CONTENT_ERROR_NONE) {
2958                 content_error("media_info_foreach_media_from_db failed: %d", ret);
2959                 media_filter_destroy(filter);
2960                 return ret;
2961         }
2962
2963         for (i = 0; i < g_list_length(all_item_list); i++) {
2964                 media_info_h media_handle = NULL;
2965                 char *media_id = NULL;
2966                 int face_count = 0;
2967
2968                 media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
2969
2970                 ret = media_info_get_media_id(media_handle, &media_id);
2971                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2972                         content_error("media_info_get_media_id failed: %d", ret);
2973
2974                 ret = media_info_get_face_count_from_db(media_id, filter, &face_count);
2975                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2976                         content_error("media_info_get_face_count_from_db failed: %d", ret);
2977
2978                 content_error("media_id [%s] face_count [%d]", media_id, face_count);
2979
2980                 ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, NULL);
2981                 if (ret != MEDIA_CONTENT_ERROR_NONE)
2982                         content_error("media_info_foreach_face_from_db failed: %d", ret);
2983
2984                 media_info_destroy(media_handle);
2985         }
2986
2987         media_filter_destroy(filter);
2988
2989         return ret;
2990 }
2991
2992 int test_face_add_del(void)
2993 {
2994         int ret = MEDIA_CONTENT_ERROR_NONE;
2995         char *media_id = "ecca7366-e085-41d8-a12b-cbdfc2b9c5fc";
2996
2997         /* Insert Test */
2998         media_face_h face = NULL;
2999
3000         char *face_tag = "test_face_tag";
3001
3002         ret = media_face_create(media_id, &face);
3003         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_face_create");
3004
3005         ret = media_face_set_face_rect(face, 10, 12, 50, 100);
3006         if (ret != MEDIA_CONTENT_ERROR_NONE)
3007                 content_error("media_face_set_face_rect failed: %d", ret);
3008
3009         ret = media_face_set_orientation(face, 5);
3010         if (ret != MEDIA_CONTENT_ERROR_NONE)
3011                 content_error("media_face_set_orientation failed: %d", ret);
3012
3013         ret = media_face_set_tag(face, face_tag);
3014         if (ret != MEDIA_CONTENT_ERROR_NONE)
3015                 content_error("media_face_set_tag failed: %d", ret);
3016
3017         ret = media_face_insert_to_db(face);
3018         if (ret != MEDIA_CONTENT_ERROR_NONE)
3019                 content_error("media_face_insert_to_db failed: %d", ret);
3020
3021         ret = media_face_destroy(face);
3022         if (ret != MEDIA_CONTENT_ERROR_NONE)
3023                 content_error("media_face_destroy failed: %d", ret);
3024
3025         /* Update Test */
3026         GList *all_item_list = NULL;
3027         filter_h filter = NULL;
3028         ret = media_filter_create(&filter);
3029         content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "fail media_filter_create");
3030
3031         ret = media_filter_set_condition(filter, "MEDIA_FACE_TAG IS NOT NULL", MEDIA_CONTENT_COLLATE_DEFAULT);
3032         if (ret != MEDIA_CONTENT_ERROR_NONE) {
3033                 media_filter_destroy(filter);
3034                 content_error("Fail to set condition");
3035                 return ret;
3036         }
3037
3038         ret = media_info_foreach_face_from_db(media_id, filter, media_face_test_cb, &all_item_list);
3039
3040         if (g_list_length(all_item_list) > 0) {
3041                 media_face_h face_handle = NULL;
3042                 face_handle = (media_face_h)g_list_nth_data(all_item_list, 0);
3043
3044                 ret = media_face_set_face_rect(face_handle, 20, 22, 70, 70);
3045                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3046                         content_error("media_face_set_face_rect failed: %d", ret);
3047                 ret = media_face_set_orientation(face_handle, 3);
3048                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3049                         content_error("media_face_set_orientation failed: %d", ret);
3050                 ret = media_face_set_tag(face_handle, NULL);
3051                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3052                         content_error("media_face_set_tag failed: %d", ret);
3053                 ret = media_face_update_to_db(face_handle);
3054                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3055                         content_error("media_face_update_to_db failed: %d", ret);
3056
3057                 media_face_destroy(face_handle);
3058         }
3059
3060         media_filter_destroy(filter);
3061
3062         /* Delete Test */
3063         char *face_id = "5e58a3a8-f0b2-4c29-b799-b49a70dc2313";
3064
3065         /* Delete Test*/
3066         ret = media_face_delete_from_db(face_id);
3067
3068         return ret;
3069 }
3070
3071 #ifdef _USE_TVPD_MODE
3072 filter_h g_tv_filter = NULL;
3073
3074 int test_tv_filter_create(void)
3075 {
3076         content_debug("\n============Filter Create============\n\n");
3077
3078         int ret = MEDIA_CONTENT_ERROR_NONE;
3079
3080         ret = media_filter_create(&g_tv_filter);
3081
3082         ret = media_filter_set_storage(g_tv_filter, "0a22a163-e634-4a2e-ba14-0469a969eea0");
3083
3084         ret = media_filter_set_order(g_tv_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_STORAGE_ID, MEDIA_CONTENT_COLLATE_DEFAULT);
3085
3086         return ret;
3087 }
3088
3089 int test_tv_filter_destroy(void)
3090 {
3091         content_debug("\n============Filter Destroy============\n\n");
3092
3093         int ret = MEDIA_CONTENT_ERROR_NONE;
3094
3095         ret = media_filter_destroy(g_tv_filter);
3096
3097         return ret;
3098 }
3099
3100 bool pvr_item_cb(media_pvr_h pvr, void *user_data)
3101 {
3102         int ret = MEDIA_CONTENT_ERROR_NONE;
3103         char *c_value = NULL;
3104         int i_value = 0;
3105         bool b_value = false;
3106         unsigned long long l_value = 0;
3107
3108         if (pvr == NULL) {
3109                 content_debug("NO Item");
3110                 return true;
3111         }
3112
3113         ret = media_pvr_get_media_id(pvr, &c_value);
3114         if (ret != MEDIA_CONTENT_ERROR_NONE)
3115                 content_error("Fail to media_pvr_get_media_id");
3116         content_debug("media_id [%s]", c_value);
3117         SAFE_FREE(c_value);
3118
3119         ret = media_pvr_get_channel_name(pvr, &c_value);
3120         if (ret != MEDIA_CONTENT_ERROR_NONE)
3121                 content_error("Fail to media_pvr_get_channel_name");
3122         content_debug("channel_name [%s]", c_value);
3123         SAFE_FREE(c_value);
3124
3125         ret = media_pvr_get_program_title(pvr, &c_value);
3126         if (ret != MEDIA_CONTENT_ERROR_NONE)
3127                 content_error("Fail to media_pvr_get_program_title");
3128         content_debug("program_title [%s]", c_value);
3129         SAFE_FREE(c_value);
3130
3131         ret = media_pvr_get_program_crid(pvr, &c_value);
3132         if (ret != MEDIA_CONTENT_ERROR_NONE)
3133                 content_error("Fail to media_pvr_get_program_crid");
3134         content_debug("program_crid [%s]", c_value);
3135         SAFE_FREE(c_value);
3136
3137         ret = media_pvr_get_guidance(pvr, &c_value);
3138         if (ret != MEDIA_CONTENT_ERROR_NONE)
3139                 content_error("Fail to media_pvr_get_guidance");
3140         content_debug("guidance [%s]", c_value);
3141         SAFE_FREE(c_value);
3142
3143         ret = media_pvr_get_synopsis(pvr, &c_value);
3144         if (ret != MEDIA_CONTENT_ERROR_NONE)
3145                 content_error("Fail to media_pvr_get_synopsis");
3146         content_debug("synopsis [%s]", c_value);
3147         SAFE_FREE(c_value);
3148
3149         ret = media_pvr_get_genre(pvr, &c_value);
3150         if (ret != MEDIA_CONTENT_ERROR_NONE)
3151                 content_error("Fail to media_pvr_get_synopsis");
3152         content_debug("genre [%s]", c_value);
3153         SAFE_FREE(c_value);
3154
3155         ret = media_pvr_get_language(pvr, &c_value);
3156         if (ret != MEDIA_CONTENT_ERROR_NONE)
3157                 content_error("Fail to media_pvr_get_language");
3158         content_debug("language [%s]", c_value);
3159         SAFE_FREE(c_value);
3160
3161         ret = media_pvr_get_path(pvr, &c_value);
3162         if (ret != MEDIA_CONTENT_ERROR_NONE)
3163                 content_error("Fail to media_pvr_get_path");
3164         content_debug("path [%s]", c_value);
3165         SAFE_FREE(c_value);
3166
3167         ret = media_pvr_get_storage_id(pvr, &c_value);
3168         if (ret != MEDIA_CONTENT_ERROR_NONE)
3169                 content_error("Fail to media_pvr_get_storage_id");
3170         content_debug("storage_id [%s]", c_value);
3171         SAFE_FREE(c_value);
3172
3173         ret = media_pvr_get_size(pvr, &l_value);
3174         if (ret != MEDIA_CONTENT_ERROR_NONE)
3175                 content_error("Fail to media_pvr_get_size");
3176         content_debug("size [%lld]", l_value);
3177
3178         ret = media_pvr_get_timezone(pvr, &i_value);
3179         if (ret != MEDIA_CONTENT_ERROR_NONE)
3180                 content_error("Fail to media_pvr_get_timezone");
3181         content_debug("timezone [%d]", i_value);
3182
3183         ret = media_pvr_get_ptc(pvr, &i_value);
3184         if (ret != MEDIA_CONTENT_ERROR_NONE)
3185                 content_error("Fail to media_pvr_get_ptc");
3186         content_debug("ptc [%d]", i_value);
3187
3188         ret = media_pvr_get_major(pvr, &i_value);
3189         if (ret != MEDIA_CONTENT_ERROR_NONE)
3190                 content_error("Fail to media_pvr_get_major");
3191         content_debug("[%d]", i_value);
3192
3193         ret = media_pvr_get_minor(pvr, &i_value);
3194         if (ret != MEDIA_CONTENT_ERROR_NONE)
3195                 content_error("Fail to media_pvr_get_minor");
3196         content_debug("minor [%d]", i_value);
3197
3198         ret = media_pvr_get_channel_type(pvr, &i_value);
3199         if (ret != MEDIA_CONTENT_ERROR_NONE)
3200                 content_error("Fail to media_pvr_get_channel_type");
3201         content_debug("channel_type [%d]", i_value);
3202
3203         ret = media_pvr_get_program_num(pvr, &i_value);
3204         if (ret != MEDIA_CONTENT_ERROR_NONE)
3205                 content_error("Fail to media_pvr_get_program_num");
3206         content_debug("program_num [%d]", i_value);
3207
3208         unsigned int ui_value = 0;
3209         ret = media_pvr_get_service_profile(pvr, &ui_value);
3210         if (ret != MEDIA_CONTENT_ERROR_NONE)
3211                 content_error("Fail to media_pvr_get_service_profile");
3212         content_debug("service_profile [%u]", ui_value);
3213
3214         ret = media_pvr_get_duration(pvr, &i_value);
3215         if (ret != MEDIA_CONTENT_ERROR_NONE)
3216                 content_error("Fail to media_pvr_get_duration");
3217         content_debug("duration [%d]", i_value);
3218
3219         ret = media_pvr_get_embargo_time(pvr, &i_value);
3220         if (ret != MEDIA_CONTENT_ERROR_NONE)
3221                 content_error("Fail to media_pvr_get_embargo_time");
3222         content_debug("embargo_time [%d]", i_value);
3223
3224         ret = media_pvr_get_expiry_time(pvr, &i_value);
3225         if (ret != MEDIA_CONTENT_ERROR_NONE)
3226                 content_error("Fail to media_pvr_get_expiry_time");
3227         content_debug("expiry_time [%d]", i_value);
3228
3229         ret = media_pvr_get_parental_rating(pvr, &i_value);
3230         if (ret != MEDIA_CONTENT_ERROR_NONE)
3231                 content_error("Fail to media_pvr_get_parental_rating");
3232         content_debug("parental_rating [%d]", i_value);
3233
3234         ret = media_pvr_get_start_time(pvr, &i_value);
3235         if (ret != MEDIA_CONTENT_ERROR_NONE)
3236                 content_error("Fail to media_pvr_get_start_time");
3237         content_debug("start_time [%d]", i_value);
3238
3239         ret = media_pvr_get_program_start_time(pvr, &i_value);
3240         if (ret != MEDIA_CONTENT_ERROR_NONE)
3241                 content_error("Fail to media_pvr_get_program_start_time");
3242         content_debug("program_start_time [%d]", i_value);
3243
3244         ret = media_pvr_get_program_end_time(pvr, &i_value);
3245         if (ret != MEDIA_CONTENT_ERROR_NONE)
3246                 content_error("Fail to media_pvr_get_program_end_time");
3247         content_debug("program_end_time [%d]", i_value);
3248
3249         ret = media_pvr_get_program_date(pvr, &i_value);
3250         if (ret != MEDIA_CONTENT_ERROR_NONE)
3251                 content_error("Fail to media_pvr_get_program_date");
3252         content_debug("program_date [%d]", i_value);
3253
3254         ret = media_pvr_get_timer_record(pvr, &b_value);
3255         if (ret != MEDIA_CONTENT_ERROR_NONE)
3256                 content_error("Fail to media_pvr_get_timer_record");
3257         content_debug("timer_record [%d]", b_value);
3258
3259         ret = media_pvr_get_series_record(pvr, &b_value);
3260         if (ret != MEDIA_CONTENT_ERROR_NONE)
3261                 content_error("Fail to media_pvr_get_series_record");
3262         content_debug("series_record [%d]", b_value);
3263
3264         ret = media_pvr_get_hd(pvr, &i_value);
3265         if (ret != MEDIA_CONTENT_ERROR_NONE)
3266                 content_error("Fail to media_pvr_get_hd");
3267         content_debug("hd [%d]", i_value);
3268
3269         ret = media_pvr_get_subtitle(pvr, &b_value);
3270         if (ret != MEDIA_CONTENT_ERROR_NONE)
3271                 content_error("Fail to media_pvr_get_subtitle");
3272         content_debug("subtitle [%d]", b_value);
3273
3274         ret = media_pvr_get_ttx(pvr, &b_value);
3275         if (ret != MEDIA_CONTENT_ERROR_NONE)
3276                 content_error("Fail to media_pvr_get_ttx");
3277         content_debug("ttx [%d]", b_value);
3278
3279         ret = media_pvr_get_ad(pvr, &b_value);
3280         if (ret != MEDIA_CONTENT_ERROR_NONE)
3281                 content_error("Fail to media_pvr_get_ad");
3282         content_debug("ad [%d]", b_value);
3283
3284         ret = media_pvr_get_hard_of_hearing_radio(pvr, &b_value);
3285         if (ret != MEDIA_CONTENT_ERROR_NONE)
3286                 content_error("Fail to media_pvr_get_hard_of_hearing_radio");
3287         content_debug("hard_of_hearing_radio [%d]", b_value);
3288
3289         ret = media_pvr_get_data_service(pvr, &b_value);
3290         if (ret != MEDIA_CONTENT_ERROR_NONE)
3291                 content_error("Fail to media_pvr_get_data_service");
3292         content_debug("data_service [%d]", b_value);
3293
3294         ret = media_pvr_get_content_lock(pvr, &b_value);
3295         if (ret != MEDIA_CONTENT_ERROR_NONE)
3296                 content_error("Fail to media_pvr_get_content_lock");
3297         content_debug("content_lock [%d]", b_value);
3298
3299         ret = media_pvr_get_content_watch(pvr, &b_value);
3300         if (ret != MEDIA_CONTENT_ERROR_NONE)
3301                 content_error("Fail to media_pvr_get_content_watch");
3302         content_debug("content_watch [%d]", b_value);
3303
3304         ret = media_pvr_get_has_audio_only(pvr, &b_value);
3305         if (ret != MEDIA_CONTENT_ERROR_NONE)
3306                 content_error("Fail to media_pvr_get_has_audio_only");
3307         content_debug("has_audio_only [%d]", b_value);
3308
3309         ret = media_pvr_get_is_local_record(pvr, &b_value);
3310         if (ret != MEDIA_CONTENT_ERROR_NONE)
3311                 content_error("Fail to media_pvr_get_is_local_record");
3312         content_debug("is_local_record [%d]", b_value);
3313
3314         ret = media_pvr_get_resolution(pvr, (media_pvr_resolution_e*)&i_value);
3315         if (ret != MEDIA_CONTENT_ERROR_NONE)
3316                 content_error("Fail to media_pvr_get_resolution");
3317         content_debug("resolution [%d]", i_value);
3318
3319         ret = media_pvr_get_aspectratio(pvr, (media_pvr_aspectratio_e*)&i_value);
3320         if (ret != MEDIA_CONTENT_ERROR_NONE)
3321                 content_error("Fail to media_pvr_get_aspectratio");
3322         content_debug("aspectratio [%d]", i_value);
3323
3324         ret = media_pvr_get_highlight(pvr, &b_value);
3325         if (ret != MEDIA_CONTENT_ERROR_NONE)
3326                 content_error("Fail to media_pvr_get_highlight");
3327         content_debug("highlight [%d]", b_value);
3328
3329
3330         return TRUE;
3331 }
3332
3333 int test_pvr()
3334 {
3335         int ret = MEDIA_CONTENT_ERROR_NONE;
3336         int media_count = 0;
3337
3338         content_debug("\n============PVR Test============\n\n");
3339
3340         test_tv_filter_create();
3341
3342         ret = media_pvr_get_media_count_from_db(g_tv_filter, &media_count);
3343         if (ret != MEDIA_CONTENT_ERROR_NONE)
3344                 content_error("media_pvr_get_media_count_from_db failed: %d", ret);
3345         else
3346                 content_debug("media_count : [%d]", media_count);
3347
3348         ret = media_pvr_foreach_media_from_db(g_tv_filter, pvr_item_cb, NULL);
3349         if (ret != MEDIA_CONTENT_ERROR_NONE)
3350                 content_error("media_pvr_foreach_media_from_db is failed");
3351
3352         test_tv_filter_destroy();
3353
3354         return ret;
3355 }
3356
3357 int test_pvr_update_db(void)
3358 {
3359         int ret = MEDIA_CONTENT_ERROR_NONE;
3360         media_pvr_h pvr = NULL;
3361
3362         ret = media_pvr_get_pvr_from_db("ff9b5a9a-a7b4-47f4-8255-84e007e25f13", &pvr);
3363         if (ret != MEDIA_CONTENT_ERROR_NONE)
3364                 content_error("media_pvr_get_pvr_from_db failed: %d", ret);
3365
3366         ret = media_pvr_set_content_lock(pvr, TRUE);
3367         if (ret != MEDIA_CONTENT_ERROR_NONE)
3368                 content_error("Fail to media_pvr_set_content_lock");
3369
3370         ret = media_pvr_set_content_watch(pvr, TRUE);
3371         if (ret != MEDIA_CONTENT_ERROR_NONE)
3372                 content_error("Fail to media_pvr_set_content_watch");
3373
3374         ret = media_pvr_set_program_title(pvr, "TEST TITLE");
3375         if (ret != MEDIA_CONTENT_ERROR_NONE)
3376                 content_error("Fail to media_pvr_set_program_title");
3377
3378         ret = media_pvr_set_highlight(pvr, TRUE);
3379         if (ret != MEDIA_CONTENT_ERROR_NONE)
3380                 content_error("Fail to media_pvr_set_highlight");
3381
3382         ret = media_pvr_update_to_db(pvr);
3383         if (ret != MEDIA_CONTENT_ERROR_NONE)
3384                 content_error("Fail to media_pvr_update_to_db");
3385
3386         if (pvr != NULL)
3387                 media_pvr_destroy(pvr);
3388
3389         return ret;
3390 }
3391 #endif
3392
3393 int main(int argc, char *argv[])
3394 {
3395         int ret = MEDIA_CONTENT_ERROR_NONE;
3396
3397         content_debug("--- content manager test start ---\n\n");
3398
3399         ret = test_connect_database();
3400         if (ret != MEDIA_CONTENT_ERROR_NONE)
3401                 return MEDIA_CONTENT_ERROR_NONE;
3402 #ifdef _USE_TVPD_MODE
3403         test_pvr();
3404
3405         test_pvr_update_db();
3406
3407         test_pvr();
3408 #endif
3409
3410 #if 0
3411         if (argc == 2) {
3412                 ret = test_ebook_text_finder(argv[1]);
3413                 if (ret != MEDIA_CONTENT_ERROR_NONE)
3414                         return ret;
3415         }
3416
3417         ret = test_start_face_detection(FALSE);
3418         if (ret != MEDIA_CONTENT_ERROR_NONE)
3419                 return ret;
3420
3421         ret = test_move();
3422         if (ret != MEDIA_CONTENT_ERROR_NONE)
3423                 return ret;
3424
3425         ret = test_gallery_scenario();
3426         if (ret != MEDIA_CONTENT_ERROR_NONE)
3427                 return ret;
3428
3429         ret = test_get_all_music_files();
3430         if (ret != MEDIA_CONTENT_ERROR_NONE)
3431                 return ret;
3432
3433         ret = test_media_info_operation();
3434         if (ret != MEDIA_CONTENT_ERROR_NONE)
3435                 return ret;
3436
3437         ret = test_folder_operation();
3438         if (ret != MEDIA_CONTENT_ERROR_NONE)
3439                 return ret;
3440
3441         ret = test_playlist_operation();
3442         if (ret != MEDIA_CONTENT_ERROR_NONE)
3443                 return ret;
3444
3445         ret = test_tag_operation();
3446         if (ret != MEDIA_CONTENT_ERROR_NONE)
3447                 return ret;
3448
3449         ret = test_bookmark_operation();
3450         if (ret != MEDIA_CONTENT_ERROR_NONE)
3451                 return ret;
3452
3453         ret = test_album_list();
3454         if (ret != MEDIA_CONTENT_ERROR_NONE)
3455                 return ret;
3456
3457         ret = test_group_operation();
3458         if (ret != MEDIA_CONTENT_ERROR_NONE)
3459                 return ret;
3460
3461         ret = test_update_operation();
3462         if (ret != MEDIA_CONTENT_ERROR_NONE)
3463                 return ret;
3464
3465         ret = test_insert();
3466         if (ret != MEDIA_CONTENT_ERROR_NONE)
3467                 return ret;
3468
3469         ret = test_move();
3470         if (ret != MEDIA_CONTENT_ERROR_NONE)
3471                 return ret;
3472
3473         ret = test_create_thumbnail(TRUE);
3474         if (ret != MEDIA_CONTENT_ERROR_NONE)
3475                 return ret;
3476
3477         ret = test_extrace_face(TRUE);
3478         if (ret != MEDIA_CONTENT_ERROR_NONE)
3479                 return ret;
3480
3481         ret = test_request_update_db();
3482         if (ret != MEDIA_CONTENT_ERROR_NONE)
3483                 return ret;
3484
3485         ret = DFT_test();
3486         if (ret != MEDIA_CONTENT_ERROR_NONE)
3487                 return ret;
3488
3489         ret = test_batch_operations();
3490         if (ret != MEDIA_CONTENT_ERROR_NONE)
3491                 return MEDIA_CONTENT_ERROR_NONE;
3492
3493         ret = test_scan_file();
3494         if (ret != MEDIA_CONTENT_ERROR_NONE)
3495                 return MEDIA_CONTENT_ERROR_NONE;
3496
3497         ret = test_scan_dir(true);
3498         if (ret != MEDIA_CONTENT_ERROR_NONE)
3499                 return MEDIA_CONTENT_ERROR_NONE;
3500
3501         ret = test_noti();
3502         if (ret != MEDIA_CONTENT_ERROR_NONE)
3503                 return MEDIA_CONTENT_ERROR_NONE;
3504
3505         ret = test_face();
3506         if (ret != MEDIA_CONTENT_ERROR_NONE)
3507                 return MEDIA_CONTENT_ERROR_NONE;
3508
3509         ret = test_face_add_del();
3510         if (ret != MEDIA_CONTENT_ERROR_NONE)
3511                 return MEDIA_CONTENT_ERROR_NONE;
3512
3513         ret = test_playlist_operation_v2();
3514         if (ret != MEDIA_CONTENT_ERROR_NONE)
3515                 return MEDIA_CONTENT_ERROR_NONE;
3516
3517         ret = test_bookmark_operation_v2();
3518         if (ret != MEDIA_CONTENT_ERROR_NONE)
3519                 return MEDIA_CONTENT_ERROR_NONE;
3520
3521         ret = test_tag_operation_v2();
3522         if (ret != MEDIA_CONTENT_ERROR_NONE)
3523                 return MEDIA_CONTENT_ERROR_NONE;
3524 #endif
3525
3526         ret = test_disconnect_database();
3527         if (ret != MEDIA_CONTENT_ERROR_NONE)
3528                 return ret;
3529
3530         content_debug("--- content manager test end ---\n");
3531
3532         return ret;
3533 }