Apply ACR comment
[platform/core/api/mtp.git] / test / mtp_unit_test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <glib.h>
6 #include <sys/time.h>
7
8 #include <mtp.h>
9 #include <mtp_internal.h>
10
11 #define BUFFER_LEN 100
12 #define TEST_CASE_MAX 39
13 #define TEST_LIST_MAX 20
14
15 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
16 #define TC_PRT(format, args...) PRT(format"\n", ##args)
17
18 #define BEGIN() TC_PRT("BEGIN >>>>");
19 #define END() TC_PRT("END <<<<");
20
21 static mtp_device_h mtp_device;
22 static mtp_storage_h mtp_storage = 0;
23 static mtp_object_h mtp_object = 0;
24 static mtp_object_h* mtp_objects;
25 int obj_count;
26
27 GMainLoop *main_loop = NULL;
28
29 typedef struct {
30         const char *tc_name;
31         int tc_code;
32         int (*tc_func)(void);
33 } tc_table_t;
34
35
36 static bool test_get_user_int(const char *msg, int *num)
37 {
38         if (msg == NULL || num == NULL)
39                 return false;
40
41         int rv;
42         char buf[32] = { 0, };
43         printf("%s\n", msg);
44         rv = read(0, buf, 32);
45
46         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
47                 return false;
48
49         *num = atoi(buf);
50         return true;
51 }
52
53 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
54 {
55         if (msg == NULL || buf == NULL || buf_size < 2)
56                 return false;
57
58         int rv;
59         printf("%s\n", msg);
60         memset(buf, 0, buf_size);
61         rv = read(0, buf, buf_size - 1);
62
63         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
64                 buf[0] = '\0';
65                 return false;
66         }
67
68         if (rv >= 0)
69                 buf[rv] = '\0';
70
71         return true;
72 }
73
74 static char *test_filetype_to_string(int type)
75 {
76         switch (type) {
77         case MTP_FILETYPE_FOLDER:                               return "MTP_FILETYPE_FOLDER";
78         case MTP_FILETYPE_WAV:                                  return "MTP_FILETYPE_WAV";
79         case MTP_FILETYPE_MP3:                                  return "MTP_FILETYPE_MP3";
80         case MTP_FILETYPE_WMA:                                  return "MTP_FILETYPE_WMA";
81         case MTP_FILETYPE_OGG:                                  return "MTP_FILETYPE_OGG";
82         case MTP_FILETYPE_AUDIBLE:                              return "MTP_FILETYPE_AUDIBLE";
83         case MTP_FILETYPE_MP4:                                  return "MTP_FILETYPE_MP4";
84         case MTP_FILETYPE_UNDEF_AUDIO:                  return "MTP_FILETYPE_UNDEF_AUDIO";
85         case MTP_FILETYPE_WMV:                                  return "MTP_FILETYPE_WMV";
86         case MTP_FILETYPE_AVI:                                  return "MTP_FILETYPE_AVI";
87         case MTP_FILETYPE_MPEG:                                 return "MTP_FILETYPE_MPEG";
88         case MTP_FILETYPE_ASF:                                  return "MTP_FILETYPE_ASF";
89         case MTP_FILETYPE_QT:                                   return "MTP_FILETYPE_QT";
90         case MTP_FILETYPE_UNDEF_VIDEO:                  return "MTP_FILETYPE_UNDEF_VIDEO";
91         case MTP_FILETYPE_JPEG:                                 return "MTP_FILETYPE_JPEG";
92         case MTP_FILETYPE_JFIF:                                 return "MTP_FILETYPE_JFIF";
93         case MTP_FILETYPE_TIFF:                                 return "MTP_FILETYPE_TIFF";
94         case MTP_FILETYPE_BMP:                                  return "MTP_FILETYPE_BMP";
95         case MTP_FILETYPE_GIF:                                  return "MTP_FILETYPE_GIF";
96         case MTP_FILETYPE_PICT:                                 return "MTP_FILETYPE_PICT";
97         case MTP_FILETYPE_PNG:                                  return "MTP_FILETYPE_PNG";
98         case MTP_FILETYPE_VCALENDAR1:                   return "MTP_FILETYPE_VCALENDAR1";
99         case MTP_FILETYPE_VCALENDAR2:                   return "MTP_FILETYPE_VCALENDAR2";
100         case MTP_FILETYPE_VCARD2:                               return "MTP_FILETYPE_VCARD2";
101         case MTP_FILETYPE_VCARD3:                               return "MTP_FILETYPE_VCARD3";
102         case MTP_FILETYPE_WINDOWSIMAGEFORMAT:   return "MTP_FILETYPE_WINDOWSIMAGEFORMAT";
103         case MTP_FILETYPE_WINEXEC:                              return "MTP_FILETYPE_WINEXEC";
104         case MTP_FILETYPE_TEXT:                                 return "MTP_FILETYPE_TEXT";
105         case MTP_FILETYPE_HTML:                                 return "MTP_FILETYPE_HTML";
106         case MTP_FILETYPE_FIRMWARE:                             return "MTP_FILETYPE_FIRMWARE";
107         case MTP_FILETYPE_AAC:                                  return "MTP_FILETYPE_AAC";
108         case MTP_FILETYPE_MEDIACARD:                    return "MTP_FILETYPE_MEDIACARD";
109         case MTP_FILETYPE_FLAC:                                 return "MTP_FILETYPE_FLAC";
110         case MTP_FILETYPE_MP2:                                  return "MTP_FILETYPE_MP2";
111         case MTP_FILETYPE_M4A:                                  return "MTP_FILETYPE_M4A";
112         case MTP_FILETYPE_DOC:                                  return "MTP_FILETYPE_DOC";
113         case MTP_FILETYPE_XML:                                  return "MTP_FILETYPE_XML";
114         case MTP_FILETYPE_XLS:                                  return "MTP_FILETYPE_XLS";
115         case MTP_FILETYPE_PPT:                                  return "MTP_FILETYPE_PPT";
116         case MTP_FILETYPE_MHT:                                  return "MTP_FILETYPE_MHT";
117         case MTP_FILETYPE_JP2:                                  return "MTP_FILETYPE_JP2";
118         case MTP_FILETYPE_JPX:                                  return "MTP_FILETYPE_JPX";
119         case MTP_FILETYPE_ALBUM:                                return "MTP_FILETYPE_ALBUM";
120         case MTP_FILETYPE_PLAYLIST:                             return "MTP_FILETYPE_PLAYLIST";
121         case MTP_FILETYPE_UNKNOWN:                              return "MTP_FILETYPE_UNKNOWN";
122         default:                                                                return "Not Supported type!!!";
123         }
124 }
125
126 int manager_test_initialize(void)
127 {
128         int ret = 0;
129
130         BEGIN();
131
132         ret = mtp_initialize();
133
134         if (ret == MTP_ERROR_NONE)
135                 TC_PRT("Initialize successful");
136         else
137                 TC_PRT("Initialize failed, ret [%d]", ret);
138
139         END();
140         return ret;
141 }
142
143 int manager_test_get_raw_devices(void)
144 {
145         int ret = 0;
146         int i;
147         mtp_raw_device_h *raw_devices = NULL;
148         int device_count;
149
150         BEGIN();
151
152         ret = mtp_get_raw_devices(&raw_devices, &device_count);
153         TC_PRT("ret[%d]: device_num[%d]", ret, device_count);
154
155         if (ret == MTP_ERROR_NONE) {
156                 for (i = 0; i < device_count; i++) {
157                         int bus_location;
158                         int device_number;
159                         char *device_name = NULL;
160                         mtp_get_bus_location(raw_devices[i], &bus_location);
161                         mtp_get_device_number(raw_devices[i], &device_number);
162                         mtp_get_device_name(raw_devices[i], &device_name);
163                         TC_PRT("device bus_location[%d], dev_no [%d], model_name[%s]",
164                                 bus_location, device_number, device_name);
165                 }
166         } else {
167                 TC_PRT("get device list failed, ret[%d]", ret);
168         }
169
170         END();
171         return ret;
172 }
173
174 int manager_test_get_device(void)
175 {
176         int ret = 0;
177         int bus_location = 0;
178         int device_number = 0;
179         int device_count;
180         mtp_raw_device_h *raw_devices = NULL;
181
182         BEGIN();
183
184         ret = mtp_get_raw_devices(&raw_devices, &device_count);
185
186         if (ret != MTP_ERROR_NONE) {
187                 TC_PRT("mtp_get_raw_devices is failed!!!");
188                 return -1;
189         }
190
191         if (device_count == 0) {
192                 TC_PRT("device is not exist!!!");
193                 END();
194                 return -1;
195         }
196
197         TC_PRT("Select first device");
198
199         mtp_get_bus_location(raw_devices[0], &bus_location);
200         mtp_get_device_number(raw_devices[0], &device_number);
201
202         TC_PRT("bus location : %d, device_number : %d", bus_location, device_number);
203
204         ret = mtp_get_device(bus_location, device_number, &mtp_device);
205         TC_PRT("ret[%d]: 1st mtp device [%d]", ret, mtp_device);
206
207         END();
208         return ret;
209 }
210
211 int manager_test_get_storages(void)
212 {
213         int i;
214         int ret = 0;
215         int bus_location = 0;
216         int device_number = 0;
217         int device_count;
218         int storage_count;
219         mtp_raw_device_h *raw_devices = NULL;
220         mtp_storage_h *mtp_storages = NULL;
221
222         ret = mtp_get_raw_devices(&raw_devices, &device_count);
223
224         if (ret != MTP_ERROR_NONE) {
225                 TC_PRT("mtp_get_raw_devices is failed!!!");
226                 return -1;
227         }
228
229         if (device_count == 0) {
230                 TC_PRT("device is not exist!!!");
231                 END();
232                 return -1;
233         }
234
235         TC_PRT("Select first device");
236
237         mtp_get_bus_location(raw_devices[0], &bus_location);
238         mtp_get_device_number(raw_devices[0], &device_number);
239
240         TC_PRT("bus location : %d, device_number : %d", bus_location, device_number);
241
242         ret = mtp_get_device(bus_location, device_number, &mtp_device);
243         TC_PRT("ret[%d]: 1st mtp device [%d]", ret, mtp_device);
244
245         ret = mtp_get_storages(mtp_device, &mtp_storages, &storage_count);
246         TC_PRT("ret[%d]: storage_count[%d]", ret, storage_count);
247
248         if (storage_count == 0) {
249                 TC_PRT("storage is not exist!!!");
250                 END();
251                 return -1;
252         }
253
254         ret = mtp_destroy_raw_devices(raw_devices);
255         TC_PRT("ret[%d]: mtp_destroy_raw_devices", ret);
256
257
258         for (i = 0; i < storage_count; i++)
259                 TC_PRT("mtp storage %d [%d]", i, mtp_storages[i]);
260
261         mtp_storage = mtp_storages[0];
262
263         END();
264         return ret;
265 }
266
267 int manager_test_get_object_handles(void)
268 {
269         int ret = 0;
270         int i;
271         int input_int = 0;
272         int *folder_list;
273         int folder_count = 0;
274         int *file_list;
275         int file_count = 0;
276         mtp_filetype_e filetype = MTP_FILETYPE_FOLDER;
277         char *filename = NULL;
278         int folder_max = 0;
279         int file_max = 0;
280         int list_max = 0;
281         BEGIN();
282
283         ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_FOLDER, mtp_object, &folder_list, &folder_count);
284         TC_PRT("ret[%d]: total folder_count[%d]", ret, folder_count);
285
286         folder_max = (folder_count < TEST_LIST_MAX) ? folder_count : TEST_LIST_MAX;
287
288         for (i = 0; i < folder_max; i++) {
289                 ret = mtp_objectinfo_get_file_name(mtp_device, folder_list[i], &filename);
290                 ret = mtp_objectinfo_get_file_type(mtp_device, folder_list[i], &filetype);
291                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
292                         ret, folder_list[i], filename, test_filetype_to_string(filetype));
293         }
294
295         ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_JPEG, mtp_object, &file_list, &file_count);
296         TC_PRT("ret[%d]: total file_count[%d]", ret, file_count);
297
298         file_max = (file_count < TEST_LIST_MAX) ? file_count : TEST_LIST_MAX;
299
300         for (i = 0; i < file_max; i++) {
301                 ret = mtp_objectinfo_get_file_name(mtp_device, file_list[i], &filename);
302                 ret = mtp_objectinfo_get_file_type(mtp_device, file_list[i], &filetype);
303                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
304                         ret, file_list[i], filename, test_filetype_to_string(filetype));
305         }
306
307         if (!test_get_user_int("==> Select Object Type(FOLDER:0, JPEG:14)"
308                         " - (Enter for skip) :", &input_int)) {
309                 TC_PRT("select default : folder[%d]", input_int);
310         }
311
312         ret = mtp_get_object_handles(mtp_device, mtp_storage, input_int, mtp_object, &mtp_objects, &obj_count);
313
314         TC_PRT("ret[%d]: total object_num[%d]", ret, obj_count);
315
316         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
317
318         for (i = 0; i < list_max; i++) {
319                 ret = mtp_objectinfo_get_file_name(mtp_device, mtp_objects[i], &filename);
320                 ret = mtp_objectinfo_get_file_type(mtp_device, mtp_objects[i], &filetype);
321                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
322                         ret, mtp_objects[i], filename, test_filetype_to_string(filetype));
323         }
324
325         if (input_int == MTP_FILETYPE_FOLDER) {
326                 if (!test_get_user_int("==> Input Object ID :", &mtp_object)) {
327                         TC_PRT("invalid input !!![%d]", mtp_object);
328                         mtp_object = 0;
329                         END();
330                         return -1;
331                 }
332                 TC_PRT("selected object id[%d]", mtp_object);
333                 TC_PRT("===== Object List - Folder =====");
334         } else {
335                 TC_PRT("===== Object List -   JPEG =====");
336         }
337
338         END();
339         return ret;
340 }
341
342 int manager_test_delete_object(void)
343 {
344         int ret = 0;
345         int i;
346         int input_int = 0;
347         mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
348         char *filename = NULL;
349         int list_max = 0;
350         BEGIN();
351
352         TC_PRT("total object_num[%d]", obj_count);
353
354         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
355
356         for (i = 0; i < list_max; i++) {
357                 ret = mtp_objectinfo_get_file_name(mtp_device, mtp_objects[i], &filename);
358                 ret = mtp_objectinfo_get_file_type(mtp_device, mtp_objects[i], &filetype);
359                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
360                         ret, mtp_objects[i], filename, test_filetype_to_string(filetype));
361         }
362
363         if (!test_get_user_int("==> Input Object ID :", &input_int)) {
364                 TC_PRT("Invalid Input !!![%d]", input_int);
365                 END();
366                 return -1;
367         }
368
369         ret = mtp_delete_object(mtp_device, input_int);
370         TC_PRT("ret[%d]: input id[%d]", ret, input_int);
371
372         END();
373         return ret;
374 }
375
376 int manager_test_get_object(void)
377 {
378         int ret = 0;
379         int i;
380         int input_int = 0;
381         mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
382         char *filename = NULL;
383         char filepath[100] = {0,};
384         int list_max = 0;
385         BEGIN();
386
387         TC_PRT("total object_num[%d]", obj_count);
388
389         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
390
391         for (i = 0; i < list_max; i++) {
392                 ret = mtp_objectinfo_get_file_name(mtp_device, mtp_objects[i], &filename);
393                 ret = mtp_objectinfo_get_file_type(mtp_device, mtp_objects[i], &filetype);
394                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
395                         ret, mtp_objects[i], filename, test_filetype_to_string(filetype));
396         }
397
398         if (!test_get_user_int("==> Input Object ID :", &input_int)) {
399                 TC_PRT("Invalid Input !!![%d]", input_int);
400                 END();
401                 return -1;
402         }
403
404         snprintf(filepath, 100, "/opt/usr/media/Downloads/JpegObject_%d.jpg", input_int);
405
406         ret = mtp_get_object(mtp_device, input_int, filepath);
407         TC_PRT("ret[%d]: input id[%d]", ret, input_int);
408
409         END();
410         return ret;
411 }
412
413
414 int manager_test_get_thumbnail(void)
415 {
416         int i;
417         int ret = 0;
418         int input_int = 0;
419         char input_str[50] = {0, };
420         char filepath[100] = {0,};
421         mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
422         char *filename = NULL;
423         int list_max = 0;
424         BEGIN();
425
426         TC_PRT("total object_num[%d]", obj_count);
427
428         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
429
430         for (i = 0; i < list_max; i++) {
431                 ret = mtp_objectinfo_get_file_name(mtp_device, mtp_objects[i], &filename);
432                 ret = mtp_objectinfo_get_file_type(mtp_device, mtp_objects[i], &filetype);
433                 TC_PRT("ret[%d]: object id[%d] - filename[%s], filetype[%s]",
434                         ret, mtp_objects[i], filename, test_filetype_to_string(filetype));
435         }
436
437         if (!test_get_user_int("==> Input JPEG ID :", &input_int)) {
438                 TC_PRT("Invalid Input !!![%d]", input_int);
439                 END();
440                 return -1;
441         }
442
443         /* String Input Test */
444         if (test_get_user_string("Input Dest File Name(ex - thumbnail or thum)"
445                 " - (Enter for skip) :", input_str, 50)) {
446                 g_strstrip(input_str);
447         } else {
448                 TC_PRT("Invalid Input !!![%s]", input_str);
449                 END();
450                 return -1;
451         }
452
453         snprintf(filepath, 100, "/opt/usr/media/Downloads/%s_%d.jpg", input_str, input_int);
454
455         ret = mtp_get_thumbnail(mtp_device, input_int, filepath);
456         TC_PRT("ret[%d]: input jpeg id[%d], input file path[%s]", ret, input_int, filepath);
457
458         END();
459         return ret;
460 }
461
462 int manager_test_deinitialize(void)
463 {
464         int ret = 0;
465         BEGIN();
466
467         ret = mtp_deinitialize();
468         TC_PRT("ret[%d] : deinitialize", ret);
469
470         END();
471         return ret;
472 }
473
474 int deviceinfo_test_get_manufacturername(void)
475 {
476         int ret = 0;
477         char *name = NULL;
478         BEGIN();
479
480         ret = mtp_deviceinfo_get_manufacturer_name(mtp_device, &name);
481         TC_PRT("ret[%d]: manufacturername[%s]", ret, name);
482
483         END();
484         return ret;
485 }
486
487 int deviceinfo_test_get_modelname(void)
488 {
489         int ret = 0;
490         char *name = NULL;
491         BEGIN();
492
493         ret = mtp_deviceinfo_get_model_name(mtp_device, &name);
494         TC_PRT("ret[%d]: modelname[%s]", ret, name);
495
496         END();
497         return ret;
498 }
499
500 int deviceinfo_test_get_serialnumber(void)
501 {
502         int ret = 0;
503         char *name = NULL;
504         BEGIN();
505
506         ret = mtp_deviceinfo_get_serial_number(mtp_device, &name);
507         TC_PRT("ret[%d]: serialnumber[%s]", ret, name);
508
509         END();
510         return ret;
511 }
512
513 int deviceinfo_test_get_deviceversion(void)
514 {
515         int ret = 0;
516         char *name = NULL;
517         BEGIN();
518
519         ret = mtp_deviceinfo_get_device_version(mtp_device, &name);
520         TC_PRT("ret[%d]: deviceversion[%s]", ret, name);
521
522         END();
523         return ret;
524 }
525
526
527 int storageinfo_test_get_description(void)
528 {
529         int ret = 0;
530         char *name = NULL;
531         BEGIN();
532
533         ret = mtp_storageinfo_get_description(mtp_device, mtp_storage, &name);
534         TC_PRT("ret[%d]: description[%s]", ret, name);
535
536         END();
537         return ret;
538 }
539
540 int storageinfo_test_get_freespace(void)
541 {
542         int ret = 0;
543         unsigned long long value = 0;
544         BEGIN();
545
546         ret = mtp_storageinfo_get_free_space(mtp_device, mtp_storage, &value);
547         TC_PRT("ret[%d]: freespace[%llu]", ret, value);
548
549         END();
550         return ret;
551 }
552
553 int storageinfo_test_get_maxcapacity(void)
554 {
555         int ret = 0;
556         unsigned long long value = 0;
557         BEGIN();
558
559         ret = mtp_storageinfo_get_max_capacity(mtp_device, mtp_storage, &value);
560         TC_PRT("ret[%d]: maxcapacity[%llu]", ret, value);
561
562         END();
563         return ret;
564 }
565
566 int storageinfo_test_get_storagetype(void)
567 {
568         int ret = 0;
569         mtp_storage_type_e value = 0;
570         BEGIN();
571
572         ret = mtp_storageinfo_get_storage_type(mtp_device, mtp_storage, &value);
573         TC_PRT("ret[%d]: storagetype[%d]", ret, value);
574
575         END();
576         return ret;
577 }
578
579 int storageinfo_test_get_volumeidentifier(void)
580 {
581         int ret = 0;
582         char *name = NULL;
583         BEGIN();
584
585         ret = mtp_storageinfo_get_volume_identifier(mtp_device, mtp_storage, &name);
586         TC_PRT("ret[%d]: volumeidentifier[%s]", ret, name);
587
588         END();
589         return ret;
590 }
591
592 int objectinfo_test_get_association_desc(void)
593 {
594         int i;
595         int ret = 0;
596         int value = 0;
597         int list_max = 0;
598         BEGIN();
599
600         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
601
602         for (i = 0; i < list_max; i++) {
603                 ret = mtp_objectinfo_get_association_desc(mtp_device, mtp_objects[i], &value);
604                 TC_PRT("ret[%d]: object id[%d] association_desc[%d]", ret, mtp_objects[i], value);
605         }
606
607         END();
608         return ret;
609 }
610
611 int objectinfo_test_get_association_type(void)
612 {
613         int i;
614         int ret = 0;
615         int value = 0;
616         int list_max = 0;
617         BEGIN();
618
619         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
620
621         for (i = 0; i < list_max; i++) {
622                 ret = mtp_objectinfo_get_association_type(mtp_device, mtp_objects[i], &value);
623                 TC_PRT("ret[%d]: object id[%d] association_type[%d]", ret, mtp_objects[i], value);
624         }
625
626         END();
627         return ret;
628 }
629
630 int objectinfo_test_get_size(void)
631 {
632         int i;
633         int ret = 0;
634         int value = 0;
635         int list_max = 0;
636         BEGIN();
637
638         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
639
640         for (i = 0; i < list_max; i++) {
641                 ret = mtp_objectinfo_get_size(mtp_device, mtp_objects[i], &value);
642                 TC_PRT("ret[%d]: object id[%d] size[%d]", ret, mtp_objects[i], value);
643         }
644
645         END();
646         return ret;
647 }
648
649 int objectinfo_test_get_parent_object_handle(void)
650 {
651         int i;
652         int ret = 0;
653         int value = 0;
654         int list_max = 0;
655         BEGIN();
656
657         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
658
659         for (i = 0; i < list_max; i++) {
660                 ret = mtp_objectinfo_get_parent_object_handle(mtp_device, mtp_objects[i], &value);
661                 TC_PRT("ret[%d]: object id[%d] parent_object_handle[%d]", ret, mtp_objects[i], value);
662         }
663
664         END();
665         return ret;
666 }
667
668 int objectinfo_test_get_storage_id(void)
669 {
670         int i;
671         int ret = 0;
672         int value = 0;
673         int list_max = 0;
674         BEGIN();
675
676         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
677
678         for (i = 0; i < list_max; i++) {
679                 ret = mtp_objectinfo_get_storage(mtp_device, mtp_objects[i], &value);
680                 TC_PRT("ret[%d]: object id[%d] mtp_storage[%d]", ret, mtp_objects[i], value);
681         }
682
683         END();
684         return ret;
685 }
686
687 int objectinfo_test_get_date_created(void)
688 {
689         int i;
690         int ret = 0;
691         int value = 0;
692         int list_max = 0;
693         BEGIN();
694
695         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
696
697         for (i = 0; i < list_max; i++) {
698                 ret = mtp_objectinfo_get_date_created(mtp_device, mtp_objects[i], &value);
699                 TC_PRT("ret[%d]: object id[%d] mtp_device[%d]", ret, mtp_objects[i], value);
700         }
701
702         END();
703         return ret;
704 }
705
706 int objectinfo_test_get_date_modified(void)
707 {
708         int i;
709         int ret = 0;
710         int value = 0;
711         int list_max = 0;
712         BEGIN();
713
714         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
715
716         for (i = 0; i < list_max; i++) {
717                 ret = mtp_objectinfo_get_date_modified(mtp_device, mtp_objects[i], &value);
718                 TC_PRT("ret[%d]: object id[%d] date_modified[%d]", ret, mtp_objects[i], value);
719         }
720
721         END();
722         return ret;
723 }
724
725 int objectinfo_test_get_file_type(void)
726 {
727         int i;
728         int ret = 0;
729         mtp_filetype_e value = 0;
730         int list_max = 0;
731         BEGIN();
732
733         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
734
735         for (i = 0; i < list_max; i++) {
736                 ret = mtp_objectinfo_get_file_type(mtp_device, mtp_objects[i], &value);
737                 TC_PRT("ret[%d]: object id[%d] file type[%d]", ret, mtp_objects[i], value);
738         }
739
740         END();
741         return ret;
742 }
743
744 int objectinfo_test_get_image_bit_depth(void)
745 {
746         int i;
747         int ret = 0;
748         int value = 0;
749         int list_max = 0;
750         BEGIN();
751
752         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
753
754         for (i = 0; i < list_max; i++) {
755                 ret = mtp_objectinfo_get_image_bit_depth(mtp_device, mtp_objects[i], &value);
756                 TC_PRT("ret[%d]: object id[%d] image_bit_depth[%d]", ret, mtp_objects[i], value);
757         }
758
759         END();
760         return ret;
761 }
762
763 int objectinfo_test_get_image_pix_width(void)
764 {
765         int i;
766         int ret = 0;
767         int value = 0;
768         int list_max = 0;
769         BEGIN();
770
771         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
772
773         for (i = 0; i < list_max; i++) {
774                 ret = mtp_objectinfo_get_image_pix_width(mtp_device, mtp_objects[i], &value);
775                 TC_PRT("ret[%d]: object id[%d] image_pix_width[%d]", ret, mtp_objects[i], value);
776         }
777
778         END();
779         return ret;
780 }
781
782 int objectinfo_test_get_image_pix_height(void)
783 {
784         int i;
785         int ret = 0;
786         int value = 0;
787         int list_max = 0;
788         BEGIN();
789
790         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
791
792         for (i = 0; i < list_max; i++) {
793                 ret = mtp_objectinfo_get_image_pix_height(mtp_device, mtp_objects[i], &value);
794                 TC_PRT("ret[%d]: object id[%d] image_pix_height[%d]", ret, mtp_objects[i], value);
795         }
796
797         END();
798         return ret;
799 }
800
801 int objectinfo_test_get_thumbnail_size(void)
802 {
803         int i;
804         int ret = 0;
805         int value = 0;
806         int list_max = 0;
807         BEGIN();
808
809         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
810
811         for (i = 0; i < list_max; i++) {
812                 ret = mtp_objectinfo_get_thumbnail_size(mtp_device, mtp_objects[i], &value);
813                 TC_PRT("ret[%d]: object id[%d] thumbnail_size[%d]", ret, mtp_objects[i], value);
814         }
815
816         END();
817         return ret;
818 }
819
820 int objectinfo_test_get_thumbnail_file_type(void)
821 {
822         int i;
823         int ret = 0;
824         mtp_filetype_e value = 0;
825         int list_max = 0;
826         BEGIN();
827
828         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
829
830         for (i = 0; i < list_max; i++) {
831                 ret = mtp_objectinfo_get_thumbnail_file_type(mtp_device, mtp_objects[i], &value);
832                 TC_PRT("ret[%d]: object id[%d] thumbnail_format[%d]", ret, mtp_objects[i], value);
833         }
834
835         END();
836         return ret;
837 }
838
839 int objectinfo_test_get_thumbnail_pix_height(void)
840 {
841         int i;
842         int ret = 0;
843         int value = 0;
844         int list_max = 0;
845         BEGIN();
846
847         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
848
849         for (i = 0; i < list_max; i++) {
850                 ret = mtp_objectinfo_get_thumbnail_pix_height(mtp_device, mtp_objects[i], &value);
851                 TC_PRT("ret[%d]: object id[%d] thumbnail_pix_height[%d]", ret, mtp_objects[i], value);
852         }
853
854         END();
855         return ret;
856 }
857
858 int objectinfo_test_get_thumbnail_pix_width(void)
859 {
860         int i;
861         int ret = 0;
862         int value = 0;
863         int list_max = 0;
864         BEGIN();
865
866         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
867
868         for (i = 0; i < list_max; i++) {
869                 ret = mtp_objectinfo_get_thumbnail_pix_width(mtp_device, mtp_objects[i], &value);
870                 TC_PRT("ret[%d]: object id[%d] thumbnail_pix_width[%d]", ret, mtp_objects[i], value);
871         }
872
873         END();
874         return ret;
875 }
876
877 int objectinfo_test_get_filename(void)
878 {
879         int i;
880         int ret = 0;
881         char *value = NULL;
882         int list_max = 0;
883         BEGIN();
884
885         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
886
887         for (i = 0; i < list_max; i++) {
888                 ret = mtp_objectinfo_get_file_name(mtp_device, mtp_objects[i], &value);
889                 TC_PRT("ret[%d]: object id[%d] filename[%s]", ret, mtp_objects[i], value);
890         }
891
892         END();
893         return ret;
894 }
895
896 int objectinfo_test_get_keywords(void)
897 {
898         int i;
899         int ret = 0;
900         char *value = NULL;
901         int list_max = 0;
902         BEGIN();
903
904         list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
905
906         for (i = 0; i < list_max; i++) {
907                 ret = mtp_objectinfo_get_keywords(mtp_device, mtp_objects[i], &value);
908                 TC_PRT("ret[%d]: object id[%d] keywords[%s]", ret, mtp_objects[i], value);
909         }
910
911         END();
912         return ret;
913 }
914
915 int application_test_get_image_from_DCIM(void)
916 {
917         int ret = 0;
918         int i;
919         mtp_filetype_e filetype = MTP_FILETYPE_FOLDER;
920         int *object_list;
921         int object_count = 0;
922         int *object_list2;
923         int object_count2 = 0;
924         char filepath[100] = {0,};
925         char *filename = NULL;
926         int selected_id = 0;
927         int input_object_id = 0;
928         int input_object_id2 = 0;
929         BEGIN();
930
931         while (true) {
932                 TC_PRT("storage_handle : %d", mtp_storage);
933
934                 if (!test_get_user_int("==> 1. Select Object type (FOLDER:0, JPEG:14, BMP:17)"
935                                 " - (Enter for skip) :", &input_object_id2)) {
936                         TC_PRT("Invalid Input !!! [%d]", input_object_id2);
937                         break;
938                 }
939
940                 ret = mtp_get_object_handles(mtp_device, (mtp_storage > 0 ? mtp_storage : 0), input_object_id2, selected_id, &object_list, &object_count);
941
942                 TC_PRT("Total object_num [%d]", object_count);
943
944                 for (i = 0; i < object_count; i++) {
945                         TC_PRT("object handle %d", object_list[i]);
946
947                         ret = mtp_objectinfo_get_file_name(mtp_device, object_list[i], &filename);
948                         ret = mtp_objectinfo_get_file_type(mtp_device, object_list[i], &filetype);
949
950                         TC_PRT("ret : %d", ret);
951                         TC_PRT("Folder object id %d - filename[%s], filetype[%s]\n", object_list[i], filename, test_filetype_to_string(filetype));
952                 }
953
954                 if (!test_get_user_int("==> 1. Input Folder Object ID (Enter for exit):", &input_object_id)) {
955                         TC_PRT("input_object_id : %d", input_object_id);
956                         g_free(object_list);
957                         break;
958                 }
959
960                 selected_id = input_object_id;
961
962                 ret = mtp_objectinfo_get_file_name(mtp_device, selected_id, &filename);
963                 ret = mtp_objectinfo_get_file_type(mtp_device, selected_id, &filetype);
964
965                 TC_PRT("ret : %d", ret);
966                 TC_PRT("selected id[%d] - filename[%s], filetype[%s]\n", selected_id, filename, test_filetype_to_string(filetype));
967
968                 g_free(filename);
969         }
970
971         ret = mtp_get_object_handles(mtp_device, (mtp_storage > 0 ? mtp_storage : 0), MTP_FILETYPE_JPEG, selected_id, &object_list2, &object_count2);
972
973         TC_PRT("Total object_num [%d]", object_count2);
974
975         for (i = 0; i < object_count2; i++) {
976                 TC_PRT("object handle %d", object_list2[i]);
977
978                 ret = mtp_objectinfo_get_file_name(mtp_device, object_list2[i], &filename);
979                 ret = mtp_objectinfo_get_file_type(mtp_device, object_list2[i], &filetype);
980
981                 TC_PRT("ret : %d", ret);
982                 TC_PRT("JPEG id[%d] - filename[%s], filetype[%s]\n", object_list2[i], filename, test_filetype_to_string(filetype));
983         }
984
985         while (true) {
986                 if (!test_get_user_int("==> 2. Input JPEG Object ID (Enter for exit):", &input_object_id2)) {
987                         TC_PRT("input_object_id2 : %d", input_object_id2);
988                         break;
989                 }
990
991                 ret = mtp_objectinfo_get_file_name(mtp_device, input_object_id2, &filename);
992                 ret = mtp_objectinfo_get_file_type(mtp_device, input_object_id2, &filetype);
993
994                 TC_PRT("ret : %d", ret);
995                 TC_PRT("selected id[%d] - filename[%s], filetype[%s]\n", input_object_id2, filename, test_filetype_to_string(filetype));
996
997                 g_free(filename);
998
999                 if (filetype == MTP_FILETYPE_JPEG) {
1000                         snprintf(filepath, 100, "/home/JpegObject_%d.jpg", input_object_id2);
1001
1002                         ret = mtp_get_object(mtp_device, input_object_id2, filepath);
1003                         TC_PRT("mtp_get_object ret : %d", ret);
1004                 }
1005         }
1006
1007         END();
1008         return ret;
1009 }
1010
1011 int application_test_get_object_handle_using_all(void)
1012 {
1013         int i;
1014         int ret = 0;
1015         int *file_list;
1016         int file_count;
1017
1018         BEGIN();
1019
1020         ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_ALL, 0, &file_list, &file_count);
1021
1022         TC_PRT("ret[%d]: total folder_count[%d]", ret, file_count);
1023         for (i = 0; i < file_count; i++)
1024                 TC_PRT("object handle [%d] : %d", file_count, file_list[i]);
1025
1026         END();
1027         return ret;
1028 }
1029
1030 int application_test_get_object_handle_using_all_image(void)
1031 {
1032         int i;
1033         int *file_list;
1034         int file_count;
1035         int ret = 0;
1036         BEGIN();
1037
1038         ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_ALL_IMAGE, 0, &file_list, &file_count);
1039
1040         TC_PRT("ret[%d]: total folder_count[%d]", ret, file_count);
1041         for (i = 0; i < file_count; i++)
1042                 TC_PRT("object handle [%d] : %d", file_count, file_list[i]);
1043
1044         END();
1045         return ret;
1046 }
1047
1048 void __test_mtp_event_cb(mtp_event_e state, int arg, void *user_data)
1049 {
1050         int ret = 0;
1051
1052         TC_PRT("state [%d] : %d", state, arg);
1053
1054         if (state == MTP_EVENT_TURNED_OFF) {
1055                 ret = mtp_deinitialize();
1056                 TC_PRT("ret[%d] : Terminated daemon", ret);
1057         }
1058 }
1059
1060 int application_test_event_callback(void)
1061 {
1062         int ret;
1063
1064         BEGIN();
1065
1066         ret = mtp_set_mtp_event_cb(__test_mtp_event_cb, NULL);
1067
1068         END();
1069
1070         return ret;
1071 }
1072
1073 tc_table_t tc_table[] = {
1074         /* manager api */
1075         {"mtp_initialize",                                                      1,      manager_test_initialize},
1076         {"mtp_get_raw_devices",                                         2,      manager_test_get_raw_devices},
1077         {"mtp_get_device",                                      3,      manager_test_get_device},
1078         {"mtp_get_storages",                                            4,      manager_test_get_storages},
1079         {"mtp_get_object_handles",                                      5,      manager_test_get_object_handles},
1080         {"mtp_delete_object",                                           6,      manager_test_delete_object},
1081         {"mtp_get_object",                                                      7,      manager_test_get_object},
1082         {"mtp_get_thumbnail",                                           8,      manager_test_get_thumbnail},
1083         {"mtp_deinitialize",                                            9,      manager_test_deinitialize},
1084
1085         /* device api */
1086         {"mtp_deviceinfo_manufacturer_name",            10,     deviceinfo_test_get_manufacturername},
1087         {"mtp_deviceinfo_model_name",                           11,     deviceinfo_test_get_modelname},
1088         {"mtp_deviceinfo_serial_number",                        12,     deviceinfo_test_get_serialnumber},
1089         {"mtp_deviceinfo_device_version",                       13,     deviceinfo_test_get_deviceversion},
1090
1091         /* storage api */
1092         {"mtp_storageinfo_get_description",                     14,     storageinfo_test_get_description},
1093         {"mtp_storageinfo_get_freespace",                       15,     storageinfo_test_get_freespace},
1094         {"mtp_storageinfo_get_maxcapacity",                     16,     storageinfo_test_get_maxcapacity},
1095         {"mtp_storageinfo_get_storagetype",                     17,     storageinfo_test_get_storagetype},
1096         {"mtp_storageinfo_get_volumeidentifier",        18,     storageinfo_test_get_volumeidentifier},
1097
1098         /* object api */
1099         {"mtp_objectinfo_get_association_desc",         19,     objectinfo_test_get_association_desc},
1100         {"mtp_objectinfo_get_association_type",         20,     objectinfo_test_get_association_type},
1101         {"mtp_objectinfo_get_size",                                     21,     objectinfo_test_get_size},
1102         {"mtp_objectinfo_get_date_created",                     22,     objectinfo_test_get_date_created},
1103         {"mtp_objectinfo_get_date_modified",            23,     objectinfo_test_get_date_modified},
1104         {"mtp_objectinfo_get_file_type",                                24,     objectinfo_test_get_file_type},
1105         {"mtp_objectinfo_get_image_pix_depth",          25,     objectinfo_test_get_image_bit_depth},
1106         {"mtp_objectinfo_get_image_pix_width",          26,     objectinfo_test_get_image_pix_width},
1107         {"mtp_objectinfo_get_image_pix_height",         27,     objectinfo_test_get_image_pix_height},
1108         {"mtp_objectinfo_get_thumbnail_size",           28,     objectinfo_test_get_thumbnail_size},
1109         {"mtp_objectinfo_get_thumbnail_format",         29,     objectinfo_test_get_thumbnail_file_type},
1110         {"mtp_objectinfo_get_thumbnail_pix_height",     30,     objectinfo_test_get_thumbnail_pix_height},
1111         {"mtp_objectinfo_get_thumbnail_pix_width",      31,     objectinfo_test_get_thumbnail_pix_width},
1112         {"mtp_objectinfo_get_filename",                         32, objectinfo_test_get_filename},
1113         {"mtp_objectinfo_get_keywords",                         33, objectinfo_test_get_keywords},
1114
1115         /* application test */
1116         {"get Jpeg image from /DCIM folder",            34,     application_test_get_image_from_DCIM},
1117         {"get object handle using ALL file type",               35,     application_test_get_object_handle_using_all},
1118         {"get object handle using ALL Image file type",         36,     application_test_get_object_handle_using_all_image},
1119         {"test callback function",              37,     application_test_event_callback},
1120         {"get object and get thumbnail test",           TEST_CASE_MAX,  NULL},
1121
1122         /*-----------*/
1123         {"Finish",                                                                      0x0000, NULL},
1124         {NULL,                                                                          0x00ff, NULL},
1125 };
1126
1127 static void tc_usage_print(void)
1128 {
1129         int i = 0;
1130
1131         while (tc_table[i].tc_name) {
1132                 if (tc_table[i].tc_code != 0x00ff)
1133                         printf("Key [%2d] : usage %s\n", tc_table[i].tc_code, tc_table[i].tc_name);
1134                 else
1135                         printf("Key [%2d] : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
1136
1137                 i++;
1138         }
1139 }
1140
1141 static int test_input_callback(void *data)
1142 {
1143         long test_id = (long)data;
1144         int ret = MTP_ERROR_NONE;
1145
1146         if ((test_id >= 1) && (test_id <= TEST_CASE_MAX)) {
1147                 TC_PRT("test_input_callback test_id : %ld", test_id);
1148
1149                 if (tc_table[test_id-1].tc_func != NULL) {
1150                         ret = tc_table[test_id-1].tc_func();
1151
1152                         if (ret != MTP_ERROR_NONE)
1153                                 TC_PRT(">>>>> Test Error Returned !!! : %d", ret);
1154                 }
1155         }
1156
1157         return 0;
1158 }
1159
1160 static int test_mtp_terminate(void)
1161 {
1162         int ret = 0;
1163
1164         TC_PRT("Finished");
1165
1166         manager_test_deinitialize();
1167         g_main_loop_quit(main_loop);
1168
1169         return ret;
1170 }
1171
1172 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1173 {
1174         char buf[BUFFER_LEN] = {0,};
1175         long test_id;
1176         int rv = 0;
1177
1178         memset(buf, 0, sizeof(buf));
1179         printf("Event received from stdin\n");
1180
1181         rv = read(0, buf, 100);
1182
1183         if (rv < 0 || buf[0] == '0') {
1184                 test_mtp_terminate();
1185                 exit(1);
1186         }
1187
1188         if (*buf == '\n' || *buf == '\r')
1189                 tc_usage_print();
1190
1191         test_id = atoi(buf);
1192
1193         test_input_callback((void *)test_id);
1194
1195         return TRUE;
1196 }
1197
1198
1199 int main(int argc, char ** argv)
1200 {
1201         GIOChannel *key_io;
1202
1203         main_loop = g_main_loop_new(NULL, FALSE);
1204         key_io = g_io_channel_unix_new(0);
1205
1206         printf("Test Thread created...\n");
1207
1208         g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL);
1209         g_main_loop_run(main_loop);
1210
1211         g_io_channel_unref(key_io);
1212         g_main_loop_unref(main_loop);
1213
1214         return 0;
1215 }