71e6d746f9b09447501ee09bfa528ee6c20a3eca
[platform/core/multimedia/libmedia-service.git] / test / test_media_info.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <glib/gstdio.h>
29 #include <pthread.h>
30 #include <sqlite3.h>
31 #include "media-svc.h"
32 #include "media-svc-util.h"
33 #include "media-svc-debug.h"
34
35 #include "audio-svc.h"
36 #include "visual-svc.h"
37
38 void test_connect_disconn();
39 int test_query(sqlite3* handle);
40 void *do_newjob();
41
42 static int _ite_cluster_fn( Mcluster* item, void* user_data) 
43 {
44         GList** list = (GList**) user_data;
45         *list = g_list_append( *list, item );
46
47         return 0;
48 }
49
50 static int _ite_fn( Mitem* item, void* user_data) 
51 {
52         GList** list = (GList**) user_data;
53         *list = g_list_append( *list, item );
54
55         return 0;
56 }
57
58 static int _ite_tag_fn(Mtag* t_item, void* user_data) 
59 {
60         GList** list = (GList**) user_data;
61         *list = g_list_append( *list, t_item );
62
63         return 0;
64 }
65
66 static int _bm_ite_fn( Mbookmark *bookmark, void *user_data )
67 {
68         if (!bookmark) {
69                 printf("bookmark is NULL!\n");
70                 return -1;
71         }
72
73         GList** list = (GList**) user_data;
74         *list = g_list_append(*list, bookmark);
75
76         return 0;
77 }
78
79 int main(int argc, char *argv[])
80 {
81         int err = -1;
82         int test_case = -1;
83         int i;
84         int count = 0;
85     GList *p_list = NULL;
86         Mtag* tag = NULL;
87         Mitem* item = NULL;
88         Mcluster* cluster = NULL;
89         minfo_cluster_filter cluster_filter;
90         minfo_item_filter item_filter;
91
92
93         if(argc < 2) return -1;
94
95         MediaSvcHandle *handle = NULL;
96         err = media_svc_connect(&handle);
97         if(err < 0) {
98                 mediainfo_dbg("media_svc_connect fails");
99         }
100
101         mediainfo_dbg("media_svc_connect succeeds");
102
103         test_case = atoi(argv[1]);
104
105         switch( test_case ) {
106                 case 0: 
107                         test_connect_disconn();
108                         break;
109                 case 1: 
110                         audio_svc_create_table(handle);
111                         break;
112                 
113                 case 2: 
114                         // Test for tag
115
116                         //err = minfo_add_tag("1bf63a42-0530-3cb8-94a1-564d603d85e8", "ZZOON");
117                         //err = minfo_add_tag("1bf63a42-0530-3cb8-94a1-564d603d85e8", "HELLO");
118
119                         //err = minfo_add_tag("2ba2cd51-e93f-af54-c1c2-b29a19fd97d0", "ZZOON");
120                         //err = minfo_rename_tag("HIHI", "ZZOON");
121                         //err = minfo_rename_tag_by_id("2ba2cd51-e93f-af54-c1c2-b29a19fd97d0", "ZZOON", "HELLOHELLO");
122                         //err = minfo_delete_tag("2ba2cd51-e93f-af54-c1c2-b29a19fd97d0", "HELLOHELLO");
123
124
125                         // Test for tag or media list
126                         err = minfo_get_media_list_by_tagname(handle, "ZZOON", FALSE, _ite_fn, &p_list);
127                         if( err < 0 ) {
128                                 printf("minfo_get_media_list_by_tagname fails : %d\n", err );
129                                 break;
130                         }
131
132                         for( i = 0; i < g_list_length(p_list); i++ ) {
133                                 item = (Mitem*)g_list_nth_data(p_list, i);
134                                 printf("media ID[%d]:%s\n", i, item->uuid );
135                                 printf("path[%d]:%s\n", i, item->file_url );
136                                 printf("display_name[%d]:%s\n", i, item->display_name );
137                         }
138
139                         g_list_free(p_list);
140                         p_list = NULL;
141
142                         printf("\n-------------------------------------------\n");
143
144                         err = minfo_get_tag_list_by_media_id(handle, "2ba2cd51-e93f-af54-c1c2-b29a19fd97d0", _ite_tag_fn, &p_list);
145                         if( err < 0 ) {
146                                 printf("minfo_get_media_list_by_tagname fails : %d\n", err );
147                                 break;
148                         }
149
150                         for( i = 0; i < g_list_length(p_list); i++ ) {
151                                 tag = (Mtag*)g_list_nth_data(p_list, i);
152                                 printf("media ID[%d]:%s\n", i, tag->media_uuid );
153                                 printf("tag name[%d]:%s\n", i, tag->tag_name );
154                                 printf("count[%d]:%d\n", i, tag->count );
155                         }
156                         g_list_free(p_list);
157                         p_list = NULL;
158
159                         printf("\n-------------------------------------------\n");
160
161                         err = minfo_get_tag_list_by_media_id(handle, "1bf63a42-0530-3cb8-94a1-564d603d85e8", _ite_tag_fn, &p_list);
162                         if( err < 0 ) {
163                                 printf("minfo_get_media_list_by_tagname fails : %d\n", err );
164                                 break;
165                         }
166
167                         for( i = 0; i < g_list_length(p_list); i++ ) {
168                                 tag = (Mtag*)g_list_nth_data(p_list, i);
169                                 printf("media ID[%d]:%s\n", i, tag->media_uuid );
170                                 printf("tag name[%d]:%s\n", i, tag->tag_name );
171                                 printf("count[%d]:%d\n", i, tag->count );
172                         }
173                         g_list_free(p_list);
174
175                         break;
176
177                 case 3:
178                         // Test for cluster
179                         printf("Test for cluster\n");
180                         memset(&cluster_filter, 0x00, sizeof(minfo_cluster_filter));
181                         //filter.sort_type =  MINFO_CLUSTER_SORT_BY_NAME_ASC;
182                         cluster_filter.sort_type =  MINFO_CLUSTER_SORT_BY_NAME_DESC;
183                         //filter.start_pos = filter.end_pos = -1;
184                         cluster_filter.start_pos = 0;
185                         cluster_filter.end_pos = 5;
186
187                         err = minfo_get_cluster_list(handle, cluster_filter, _ite_cluster_fn, &p_list);
188                         if( err < 0 ) {
189                                 printf("minfo_get_cluster_list fail : %d\n", err);
190                                 break;
191                         }
192
193                         for( i = 0; i < g_list_length(p_list); i++ ) {
194                                 cluster = (Mcluster*)g_list_nth_data(p_list, i);
195                                 printf("cluster UUID[%d]:%s\n", i,  cluster->uuid );
196                                 printf("display_name[%d]:%s\n", i, cluster->display_name );
197                         }
198
199                         break;
200
201                 case 4:
202                         // Test for multi-threads
203                         printf("Test for multi-threads\n");
204                         pthread_t p_thread[1];
205                         int thr_id;
206                         int status;
207                         //int media_id = 1;
208                         const char *media_id = "2b0a4efe-c3cb-cb62-fe12-3f4f7aef4ab9";
209
210                         thr_id = pthread_create(&p_thread[0], NULL, do_newjob, NULL);
211
212                         pthread_join(p_thread[0], (void **) &status);
213
214                         err = minfo_update_media_name(handle, media_id, "New.JPG");
215                         if( err < 0)
216                         {
217                                 printf("minfo_update_media_name failed\n");
218                                 return err;
219                         }
220                         
221                         break;
222
223                 case 5:
224                         printf("Test minfo_get_item_list\n");
225                         memset(&item_filter, 0x00, sizeof(minfo_item_filter));
226
227                         item_filter.file_type =  MINFO_ITEM_ALL;
228                         item_filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_ASC;
229                         item_filter.start_pos = 0;
230                         item_filter.end_pos = 10;
231                         item_filter.with_meta = 0;
232                         item_filter.favorite = MINFO_MEDIA_FAV_ALL;
233                         const char *_id = "fae82467-6e74-475c-8414-40f011130c6d";
234
235                         //get a set of items
236                         err = minfo_get_item_list(handle, _id, item_filter, _ite_fn, &p_list);
237                         if( err < 0)
238                         {
239                                 printf("minfo_get_item_list failed\n");
240                                 return err;
241                         }
242
243                         if( p_list == NULL ) printf("failed!\n");
244         
245                         for( i = 0; i < g_list_length(p_list); i++ ) {
246                                 item = (Mitem*)g_list_nth_data(p_list, i);
247                                 printf("media ID[%d]:%s\n", i, item->uuid );
248                                 printf("path[%d]:%s\n", i, item->file_url );
249                                 printf("display_name[%d]:%s\n", i, item->display_name );
250                                 printf("size[%d]:%d\n", i, item->size );
251                                 printf("thumb url[%d]:%s(length:%d)\n", i, item->thumb_url, strlen(item->thumb_url) );
252                         }
253         
254                         /* delete list to avoid memory leak */
255                         for( i = 0; i < g_list_length(p_list); i++ ) {
256                                 item = (Mitem*)g_list_nth_data(p_list, i);
257                                 minfo_destroy_mtype_item(item);
258                         }
259         
260                         g_list_free(p_list);
261                         p_list = NULL;
262
263                         break;
264                 
265                 case 6:
266                         printf("Test minfo_get_all_item_list\n");
267                         memset(&item_filter, 0x00, sizeof(minfo_item_filter));
268
269                         item_filter.file_type = MINFO_ITEM_ALL;
270                         item_filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_ASC;
271                         item_filter.start_pos = 0;
272                         item_filter.end_pos = 10;
273                         item_filter.with_meta = true;
274                         item_filter.favorite = MINFO_MEDIA_FAV_ALL;
275
276                         //get a set of items
277                         err = minfo_get_all_item_list(handle, MINFO_CLUSTER_TYPE_ALL, item_filter, _ite_fn, &p_list);
278                         if( err < 0)
279                         {
280                                 printf("minfo_get_all_item_list failed\n");
281                                 return err;
282                         }
283
284                         if( p_list == NULL ) printf("failed!\n");
285         
286                         for( i = 0; i < g_list_length(p_list); i++ ) {
287                                 item = (Mitem*)g_list_nth_data(p_list, i);
288                                 printf("media ID[%d]:%s\n", i, item->uuid );
289                                 printf("path[%d]:%s\n", i, item->file_url );
290                                 printf("display_name[%d]:%s\n", i, item->display_name );
291                                 printf("size[%d]:%d\n", i, item->size );
292                                 printf("thumb url[%d]:%s(length:%d)\n", i, item->thumb_url, strlen(item->thumb_url) );
293
294                                 if (item->type == MINFO_ITEM_VIDEO) {
295                                         printf("genre : %s\n", item->meta_info->video_info->genre);
296                                 }
297                         }
298         
299                         /* delete list to avoid memory leak */
300                         for( i = 0; i < g_list_length(p_list); i++ ) {
301                                 item = (Mitem*)g_list_nth_data(p_list, i);
302                                 minfo_destroy_mtype_item(item);
303                         }
304         
305                         g_list_free(p_list);
306                         p_list = NULL;
307                         break;
308
309                 case 7:
310                         printf("Test minfo_delete_media_id\n");
311                         
312                         err = minfo_delete_media_id(handle, "12ca468c-994d-f62c-7229-a361c3a6c2a1");
313                         if( err < 0)
314                         {
315                                 printf("minfo_delete_media_id failed\n");
316                                 return err;
317                         }
318                         break;
319
320                 case 8:
321                         // Test for cluster
322                         printf("Test for minfo_get_cluster\n");
323                         Mcluster *cluster = NULL;
324
325                         err = minfo_get_cluster(handle, NULL, NULL, &cluster);
326                         if( err < 0 ) {
327                                 printf("minfo_get_cluster_list fail : %d\n", err);
328                                 break;
329                         }
330
331                         break;
332
333                 case 9:
334                         printf("Test minfo_get_media_list_by_tagname_with_filter\n");
335
336                         GList *p_list = NULL;
337                         minfo_tag_filter filter;
338                 
339                         filter.start_pos = 1;
340                         filter.end_pos = 3;
341                         filter.file_type =  MINFO_ITEM_VIDEO;
342                         filter.with_meta = 0;
343                 
344                         //get a media items' list who are included to the same tag with 'test tag'.
345                         err = minfo_get_media_list_by_tagname_with_filter(handle, "gd", filter, _ite_fn, &p_list);
346                         if (err < 0)
347                         {
348                                 printf( "failed to get a media items' list. error code->%d", err);
349                                 break;
350                         }
351                         
352                         for( i = 0; i < g_list_length(p_list); i++ ) {
353                                 item = (Mitem*)g_list_nth_data(p_list, i);
354                                 printf("media ID[%d]:%s\n", i, item->uuid );
355                                 printf("path[%d]:%s\n", i, item->file_url );
356                                 printf("display_name[%d]:%s\n", i, item->display_name );
357                         }
358
359                         g_list_free(p_list);
360                         p_list = NULL;
361
362                         break;
363
364                 case 10:
365                         printf("Test get count\n");
366                         count = 0;
367                         const char *cluster_id = "8ddcdba9-9df4-72b4-4890-8d21d13854ad";
368                         minfo_cluster_filter c_filter;
369                         minfo_item_filter m_filter;
370
371                         memset(&c_filter, 0x00, sizeof(minfo_cluster_filter));
372                         c_filter.cluster_type = MINFO_CLUSTER_TYPE_ALL;
373                         c_filter.sort_type =  MINFO_CLUSTER_SORT_BY_NAME_DESC;
374                         c_filter.start_pos = c_filter.end_pos = -1;
375
376                         memset(&m_filter, 0x00, sizeof(minfo_item_filter));
377                         m_filter.file_type =  MINFO_ITEM_ALL;
378                         m_filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_ASC;
379                         m_filter.start_pos = -1;
380                         m_filter.end_pos = -1;
381                         m_filter.with_meta = 0;
382                         m_filter.favorite = MINFO_MEDIA_FAV_ALL;
383
384                         err = minfo_get_cluster_cnt(handle, c_filter, &count);
385
386                         if (err < 0) {
387                                 printf( "failed to get a media items' list. error code->%d", err);
388                         } else {
389                                 printf( "Clouster count : %d\n", count);
390                         }
391
392                         err = minfo_get_item_cnt(handle, cluster_id, m_filter, &count);
393
394                         if (err < 0) {
395                                 printf( "failed to get a media items' list. error code->%d", err);
396                         } else {
397                                 printf( "media count in cluster[%s] : %d\n", cluster_id, count);
398                         }
399
400                         break;
401
402         case 11:
403                 printf("test minfo_add_media\n");
404                 char path[255];
405                 int type;
406                 while(1) {
407                         printf("Enter path and type(  \"exit 0\" to quit ) : ");
408                         scanf("%s %d", path, &type);
409
410                         if( strcmp(path, "exit") == 0 ) break;
411
412                         struct timeval time1;
413                         struct timeval time2;
414                         gettimeofday(&time1, NULL);
415
416                         err = minfo_add_media(handle, path, type);
417                         if( err < 0 ) {
418                                 printf("minfo_add_media fails ( path : %s, type : %d )\n", path, type );
419                         } else {
420                                 printf("minfo_add_media succeed ( path : %s, type : %d )\n", path, type );
421                         }
422
423                         gettimeofday(&time2, NULL);
424
425                         printf("Time : %ld\n", (time2.tv_sec * 1000000 + time2.tv_usec) - 
426                                                                         (time1.tv_sec * 1000000 + time1.tv_usec));
427                 }
428
429                 break;
430
431         case 12:
432                 printf("Test minfo_delete_media_id\n");
433
434                 char inserted_media_uuid[256] = {0,};
435                 printf("Enter media id: ");
436                 scanf("%s", inserted_media_uuid);
437
438                 err = minfo_delete_media_id(handle, inserted_media_uuid);
439                 if( err < 0 ) {
440                         printf("minfo_delete_media_id fails\n");
441                 } else {
442                         printf("minfo_delete_media_id succeeds\n");
443                 }
444
445                 break;
446
447         case 13:
448         {
449                 printf("test minfo_add_web_media\n");
450                 //char path[255];
451                 //int type;
452                 const char *cluster_id = "8ddcdba9-9df4-72b4-4890-8d21d13854ad";
453
454                 //add a web media to a web album.
455                 err = minfo_add_web_media_with_type(handle, cluster_id, "http://user/specifying/address",  "web_media", MINFO_ITEM_IMAGE, "thumbnail name");
456                 if (err < 0)
457                 {
458                         printf( "failed to add to a web album. error code->%d", err);
459                 }
460         }
461         break;
462
463         case 14:
464         {
465                 printf("test minfo_update_cluster_name\n");
466                 //char path[255];
467                 //int type;
468
469                 //add a web media to a web album.
470                 err = minfo_update_cluster_name(handle, "8ddcdba9-9df4-72b4-4890-8d21d13854ad", "hey");
471                 if (err < 0)
472                 {
473                         printf( "failed to add to a web album. error code->%d", err);
474                 }
475         }
476         break;
477
478         case 15:
479         {
480                 printf("test to get the latest item in camera shots\n");                
481                 char cluster_id[256] = {0,};
482
483                 //add a web media to a web album.
484                 err = minfo_get_cluster_id_by_url(handle, "/opt/media/Images and videos/hey", cluster_id, sizeof(cluster_id));
485                 if (err < 0)
486                 {
487                         printf( "failed to minfo_get_cluster_id_by_url. error code->%d", err);
488                         break;
489                 }
490
491                 printf("Cluster ID : %s\n", cluster_id);
492
493                 memset(&item_filter, 0x00, sizeof(minfo_item_filter));
494
495                 item_filter.file_type = MINFO_ITEM_ALL;
496                 item_filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
497                 item_filter.start_pos = 0;
498                 item_filter.end_pos = 1;
499                 item_filter.with_meta = false;
500                 item_filter.favorite = MINFO_MEDIA_FAV_ALL;
501                 p_list = NULL;
502                 //get a set of items
503                 err = minfo_get_item_list(handle, cluster_id, item_filter, _ite_fn, &p_list);
504                 if( err < 0)
505                 {
506                         printf("minfo_get_item_list failed\n");
507                         return err;
508                 }
509
510                 if( p_list == NULL ) printf("failed!\n");
511
512                 for( i = 0; i < g_list_length(p_list); i++ ) {
513                         item = (Mitem*)g_list_nth_data(p_list, i);
514                         printf("media ID[%d]:%s\n", i, item->uuid );
515                         printf("path[%d]:%s\n", i, item->file_url );
516                         printf("display_name[%d]:%s\n", i, item->display_name );
517                 }
518
519                 /* delete list to avoid memory leak */
520                 for( i = 0; i < g_list_length(p_list); i++ ) {
521                         item = (Mitem*)g_list_nth_data(p_list, i);
522                         minfo_destroy_mtype_item(item);
523                 }
524
525                 g_list_free(p_list);
526                 p_list = NULL;
527         }
528         break;
529         
530         case 16:
531         {
532                 printf("Test minfo_get_item_list_search\n");
533                 memset(&item_filter, 0x00, sizeof(minfo_item_filter));
534
535                 const char *search_str = "Ima";
536                 minfo_search_field_t search_field = MINFO_SEARCH_BY_HTTP_URL | MINFO_SEARCH_BY_PATH | MINFO_SEARCH_BY_NAME;
537                 minfo_folder_type folder_type = MINFO_CLUSTER_TYPE_ALL;
538
539                 item_filter.file_type =  MINFO_ITEM_ALL;
540                 item_filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
541                 item_filter.start_pos = 0;
542                 item_filter.end_pos = 9;
543                 item_filter.with_meta = 0;
544                 item_filter.favorite = MINFO_MEDIA_FAV_ALL;
545                 p_list = NULL;
546
547                 //get a set of items
548                 err = minfo_get_item_list_search(handle, search_field, search_str, folder_type, item_filter, _ite_fn, &p_list);
549                 if (err < 0) {
550                         printf("minfo_get_item_list_search failed\n");
551                         return err;
552                 }
553
554                 if (p_list == NULL) printf("failed!\n");
555                 else printf("success\n");
556
557                 for (i = 0; i < g_list_length(p_list); i++) {
558                         item = (Mitem*)g_list_nth_data(p_list, i);
559                         printf("media ID[%d]:%s\n", i, item->uuid );
560                         printf("path[%d]:%s\n", i, item->file_url );
561                         printf("display_name[%d]:%s\n", i, item->display_name );
562                         printf("thumb url[%d]:%s(length:%d)\n", i, item->thumb_url, strlen(item->thumb_url) );
563                 }
564
565                 /* delete list to avoid memory leak */
566                 for (i = 0; i < g_list_length(p_list); i++) {
567                         item = (Mitem*)g_list_nth_data(p_list, i);
568                         minfo_destroy_mtype_item(item);
569                 }
570
571                 g_list_free(p_list);
572                 p_list = NULL;
573
574                 break;
575         }
576
577         case 17:
578         {
579                 printf("test minfo_update_image_meta_info_int\n");
580                 const char *media_uuid = "12ca468c-994d-f62c-7229-a361c3a6c2a1";
581                 int width = 640;
582                 int height = 480;
583
584                 //add a web media to a web album.
585                 err = minfo_update_image_meta_info_int(handle, media_uuid, MINFO_IMAGE_META_WIDTH, width,
586                                                                                                 MINFO_IMAGE_META_HEIGHT, height, -1);
587                 if (err < 0) {
588                         printf( "minfo_update_image_meta_info_int failed->%d\n", err);
589                 } else {
590                         printf( "minfo_update_image_meta_info_int success\n");
591                 }
592
593                 break;
594         }
595
596         case 18:
597         {
598                 printf("test _media_info_generate_uuid\n");
599                 printf("UUID : %s\n", (char*)_media_info_generate_uuid());
600                 break;
601         }
602
603         case 19:
604                 printf("test minfo_get_bookmark_list\n");
605         GList *_list = NULL;
606                 const char *media_uuid = NULL;
607
608                 p_list = NULL;
609                 if (p_list) printf("p list does exist\n");
610                 if (argv[2]) {
611                         media_uuid = argv[2];
612                 } else {
613                         printf("please insert media id\n");
614                         break;
615                 }
616
617                 //add a web media to a web album.
618                 err = minfo_get_bookmark_list(handle, media_uuid, _bm_ite_fn, &_list);
619                 if (err < 0) {
620                         printf( "minfo_get_bookmark_list failed->%d\n", err);
621                 } else {
622                         printf( "minfo_get_bookmark_list success\n");
623                         
624                         if (_list) {
625                         int i;
626                         Mbookmark* bm = NULL;
627                         for( i = 0; i < g_list_length(_list); i++ ) {
628                                 bm = (Mbookmark*)g_list_nth_data(_list, i);
629                                 printf("Thumb[%d]:%s\n", i, bm->thumb_url );
630                         }
631                         }
632                 }
633
634                 break;
635
636         case 20:
637                 printf("test minfo_get_item\n");
638                 Mitem *mitem = NULL;
639                 const char *url = "/opt/media/Images and videos/My video clips/Helicopter.mp4";
640
641                 err = minfo_get_item(handle, url, &mitem);
642
643                 if (err < 0) {
644                         printf("minfo_get_item failed");
645                         return -1;
646                 }
647
648                 printf("mitem->path : %s\n", mitem->file_url);
649                 printf("mitem->display_name : %s\n", mitem->display_name);
650                 break;
651         case 21:
652                 printf("test minfo_get_all_item_conut\n");
653                 int cnt = 0;
654                 minfo_folder_type f_type = MINFO_CLUSTER_TYPE_LOCAL_ALL;
655                 //minfo_folder_type f_type = MINFO_CLUSTER_TYPE_LOCAL_PHONE;
656                 //minfo_media_favorite_type fav_type = MINFO_MEDIA_FAV_ALL;
657                 minfo_media_favorite_type fav_type = MINFO_MEDIA_FAV_ONLY;
658                 
659                 minfo_file_type file_type = MINFO_ITEM_ALL;
660                 //minfo_file_type file_type = MINFO_ITEM_IMAGE;
661
662                 err = minfo_get_all_item_count(handle, f_type, file_type, fav_type, &cnt);
663
664                 if (err < 0) {
665                         printf("minfo_get_all_item_conut failed");
666                         return -1;
667                 }
668
669                 printf("count : %d\n", cnt);
670                 break;
671
672         case 36:
673                 printf("test minfo_get_thumb_path \n");
674                 char thumb_path[255] = {0,};
675
676                 if(argv[2] && argv[3]) {
677                         int type = atoi(argv[3]);
678                         if( type == 1 ) {
679                                 err = minfo_get_thumb_path(handle, argv[2], thumb_path, 255);
680                         } else if( type == 2) {
681                                 err = minfo_get_thumb_path_for_video(handle, argv[2], thumb_path, 255);
682                         } else {
683                                 printf("minfo_get_thumb_path fails( invalid type )\n" );
684                                 return -1;
685                         }
686                         if(err < 0)
687                         {
688                                 printf("minfo_get_thumb_path fails\n" );
689                                 return -1;
690                         }
691                 }
692
693                 printf("minfo_get_thumb_path : %s\n", thumb_path);
694                 break;
695
696         case 37:
697                 printf("test minfo_delete_invalid_media_records \n");
698                 
699                 err = minfo_delete_invalid_media_records(handle, 1);
700
701                 if(err < 0)
702                 {
703                         printf("minfo_delete_invalid_media_records fails\n");
704                         return -1;
705                 }
706                 
707
708                 printf("minfo_delete_invalid_media_records succeeds.\n");
709                 break;
710
711         /* ------------------- Test for audio ---------------- */
712         case 101:
713         {
714                 printf("test audio_svc_insert_item\n");
715                 char path[255];
716
717                 while(1) {
718                         printf("Enter path (  \"exit\" to quit ) : ");
719                         scanf("%s", path );
720
721                         if( strcmp(path, "exit") == 0 ) break;
722
723                         err = audio_svc_insert_item(handle, AUDIO_SVC_STORAGE_PHONE, path, AUDIO_SVC_CATEGORY_MUSIC);
724                         if (err != AUDIO_SVC_ERROR_NONE) {
725                                 fprintf(stderr,"[errer to insert music] : %s\n", path);
726                         }
727                 }
728         }
729         break;
730
731         case 102:
732         {
733                 printf("test audio_svc_delete_item_by_path\n");
734                 char path[255];
735
736                 while(1) {
737                         printf("Enter path (  \"exit\" to quit ) : ");
738                         scanf("%s", path );
739
740                         if( strcmp(path, "exit") == 0 ) break;
741
742                         err = audio_svc_delete_item_by_path(handle, path);
743                         if (err != AUDIO_SVC_ERROR_NONE) {
744                                 fprintf(stderr,"[errer to delete music] : %s\n", path);
745                         }
746                 }
747         }
748         break;
749
750         case 103:
751         {
752                 printf("test audio_svc_get_list_item - AUDIO_SVC_TRACK_BY_SEARCH\n");
753                 int offset = 0, count = 10, i = 0;
754                 const char *str = "Sa";
755                 AudioHandleType *a_handle = NULL;
756
757                 err = audio_svc_search_item_new(&a_handle, count);
758                 if (err < 0) {
759                         printf("audio_svc_search_item_new failed:%d\n", err);
760                         return err;
761                 }
762
763                 err = audio_svc_list_by_search(handle, a_handle, AUDIO_SVC_ORDER_BY_TITLE_ASC, offset, count, AUDIO_SVC_SEARCH_TITLE, str, strlen(str), AUDIO_SVC_SEARCH_ALBUM, str, strlen(str), AUDIO_SVC_SEARCH_ARTIST, str, strlen(str), -1);
764
765                 if (err != AUDIO_SVC_ERROR_NONE) {
766                         mediainfo_dbg("Fail to get items : %d", err);
767                         return err;
768                 }
769                 
770                 for (i = 0; i < count; i++) {
771                         AudioHandleType *item = NULL;
772                         err = audio_svc_search_item_get(handle, i, &item);
773                         char *title = NULL, *artist = NULL, *pathname = NULL, *album = NULL;
774                         char *audio_id = NULL;
775                         int size = 0;
776
777                         if (err < 0) {
778                                 printf("[%d] audio_svc_search_item_get failed : %d\n", i, err);
779                         } else {
780                                 audio_svc_item_get_val(item,  
781                                                 AUDIO_SVC_TRACK_DATA_AUDIO_ID, &audio_id, &size,
782                                                 AUDIO_SVC_TRACK_DATA_PATHNAME, &pathname, &size,
783                                                 AUDIO_SVC_TRACK_DATA_TITLE, &title, &size,
784                                                 AUDIO_SVC_TRACK_DATA_ARTIST, &artist, &size,
785                                                 AUDIO_SVC_TRACK_DATA_ALBUM, &album, &size,
786                                                 -1);
787
788                                 if( audio_id == NULL ) break;
789
790                                 printf("[%d] ID: %s\n", i, audio_id);
791                                 printf("[%d] Path: %s\n", i, pathname);
792                                 printf("[%d] Title: %s\n", i, title);
793                                 printf("[%d] Artist: %s\n", i, artist);
794                                 printf("[%d] Album: %s\n", i, album);
795                         }
796                 }
797
798                 audio_svc_search_item_free(handle); 
799         }
800         break;
801
802         case 104:
803         {
804 #if 0
805                         printf("Test audio_svc_update_item_metadata\n");
806                         count = 4;
807                         
808                         err = audio_svc_update_item_metadata(31, AUDIO_SVC_TRACK_DATA_PLAYED_COUNT, count, -1);
809
810                         if( err < 0)
811                         {
812                                 printf("audio_svc_update_item_metadata failed\n");
813                                 return err;
814                         } else {
815                                 printf("play count is now %d\n", count);
816                         }
817 #endif
818         }       
819         break;
820
821         default:
822                 break;
823         }
824
825         err = media_svc_disconnect(handle);
826         if(err < 0) {
827                 mediainfo_dbg("media_svc_disconnect fails");
828         }
829
830         printf("End of Test\n");
831     return err;
832 }
833
834 void *do_newjob()
835 {
836         int err;
837         
838         MediaSvcHandle *handle = NULL;
839         err = media_svc_connect(&handle);
840         if(err < 0) {
841                 mediainfo_dbg("media_svc_connect fails");
842         }
843
844         const char *media_id = "2b0a4efe-c3cb-cb62-fe12-3f4f7aef4ab9";
845
846         err = minfo_update_media_name(handle, media_id, "New1.JPG");
847         if( err < 0)
848         {
849                 printf("minfo_update_media_name failed\n");
850                 return NULL;
851         }
852
853         printf("Calling media_svc_disconnect in do_newjob \n");
854         err = media_svc_disconnect(handle);
855         if(err < 0) {
856                 mediainfo_dbg("media_svc_disconnect fails");
857                 return NULL;
858         }
859
860         printf("do_newjob done\n");
861
862         return NULL;
863 }
864
865
866 void test_connect_disconn()
867 {
868         mediainfo_dbg("");
869         int err = -1;
870         MediaSvcHandle *handle = NULL;
871         err = media_svc_connect(&handle);
872         if( err < 0 ) {
873                 mediainfo_dbg("Error");
874                 return;
875         } else { mediainfo_dbg("success"); }
876
877         if(handle == NULL) mediainfo_dbg("NULL!!!!!");
878         test_query((sqlite3 *)handle);
879
880         err = media_svc_disconnect(handle);
881         if( err < 0 ) {
882                 mediainfo_dbg("Error");
883                 return;
884         }
885
886         mediainfo_dbg("test_connect_disconn success");
887
888         return;
889 }
890
891 int test_query(sqlite3* handle)
892 {
893         int err = -1;
894         sqlite3_stmt* stmt = NULL;
895         char query_string[255];
896         memset(query_string, 0, sizeof(query_string) );
897
898         if( handle == NULL ) {
899                 mediainfo_dbg( "handle is NULL" );
900                 return -1;
901         }
902
903         snprintf(query_string, sizeof(query_string), "select * from visual_folder where storage_type = 0");
904
905         err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);      
906
907         if (SQLITE_OK != err) 
908         {
909                  mediainfo_dbg ("prepare error [%s]\n", sqlite3_errmsg(handle));
910                  mediainfo_dbg ("query string is %s\n", query_string);
911                  return -1;
912         }
913         err = sqlite3_step(stmt);       
914         if (err != SQLITE_ROW) 
915         {
916                  mediainfo_dbg ("end of row [%s]\n", sqlite3_errmsg(handle));
917                  mediainfo_dbg ("query string is %s\n", query_string);
918                  sqlite3_finalize(stmt);
919                  return -1;
920         }
921
922         mediainfo_dbg("ID: %d", sqlite3_column_int (stmt, 0));
923         mediainfo_dbg("Display name: %s", (const char*)sqlite3_column_text (stmt, 2));
924
925         if(err < 0)
926         {
927                 mediainfo_dbg ("mb-svc load data failed");
928                 sqlite3_finalize(stmt);
929                 return -1;
930         }
931
932         sqlite3_finalize(stmt);
933
934         return 0;
935 }
936