9 #include <mtp_internal.h>
11 #define BUFFER_LEN 100
12 #define TEST_CASE_MAX 39
13 #define TEST_LIST_MAX 20
15 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
16 #define TC_PRT(format, args...) PRT(format"\n", ##args)
18 #define BEGIN() TC_PRT("BEGIN >>>>");
19 #define END() TC_PRT("END <<<<");
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;
27 GMainLoop *main_loop = NULL;
36 static bool test_get_user_int(const char *msg, int *num)
38 if (msg == NULL || num == NULL)
42 char buf[32] = { 0, };
44 rv = read(0, buf, 32);
46 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
53 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
55 if (msg == NULL || buf == NULL || buf_size < 2)
60 memset(buf, 0, buf_size);
61 rv = read(0, buf, buf_size - 1);
63 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
74 static char *test_filetype_to_string(int 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!!!";
126 int manager_test_initialize(void)
132 ret = mtp_initialize();
134 if (ret == MTP_ERROR_NONE)
135 TC_PRT("Initialize successful");
137 TC_PRT("Initialize failed, ret [%d]", ret);
143 int manager_test_get_raw_devices(void)
147 mtp_raw_device_h *raw_devices = NULL;
152 ret = mtp_get_raw_devices(&raw_devices, &device_count);
153 TC_PRT("ret[%d]: device_num[%d]", ret, device_count);
155 if (ret == MTP_ERROR_NONE) {
156 for (i = 0; i < device_count; i++) {
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);
167 TC_PRT("get device list failed, ret[%d]", ret);
174 int manager_test_get_device(void)
177 int bus_location = 0;
178 int device_number = 0;
180 mtp_raw_device_h *raw_devices = NULL;
184 ret = mtp_get_raw_devices(&raw_devices, &device_count);
186 if (ret != MTP_ERROR_NONE) {
187 TC_PRT("mtp_get_raw_devices is failed!!!");
191 if (device_count == 0) {
192 TC_PRT("device is not exist!!!");
197 TC_PRT("Select first device");
199 mtp_get_bus_location(raw_devices[0], &bus_location);
200 mtp_get_device_number(raw_devices[0], &device_number);
202 TC_PRT("bus location : %d, device_number : %d", bus_location, device_number);
204 ret = mtp_get_device(bus_location, device_number, &mtp_device);
205 TC_PRT("ret[%d]: 1st mtp device [%d]", ret, mtp_device);
211 int manager_test_get_storages(void)
215 int bus_location = 0;
216 int device_number = 0;
219 mtp_raw_device_h *raw_devices = NULL;
220 mtp_storage_h *mtp_storages = NULL;
222 ret = mtp_get_raw_devices(&raw_devices, &device_count);
224 if (ret != MTP_ERROR_NONE) {
225 TC_PRT("mtp_get_raw_devices is failed!!!");
229 if (device_count == 0) {
230 TC_PRT("device is not exist!!!");
235 TC_PRT("Select first device");
237 mtp_get_bus_location(raw_devices[0], &bus_location);
238 mtp_get_device_number(raw_devices[0], &device_number);
240 TC_PRT("bus location : %d, device_number : %d", bus_location, device_number);
242 ret = mtp_get_device(bus_location, device_number, &mtp_device);
243 TC_PRT("ret[%d]: 1st mtp device [%d]", ret, mtp_device);
245 ret = mtp_get_storages(mtp_device, &mtp_storages, &storage_count);
246 TC_PRT("ret[%d]: storage_count[%d]", ret, storage_count);
248 if (storage_count == 0) {
249 TC_PRT("storage is not exist!!!");
254 ret = mtp_destroy_raw_devices(raw_devices);
255 TC_PRT("ret[%d]: mtp_destroy_raw_devices", ret);
258 for (i = 0; i < storage_count; i++)
259 TC_PRT("mtp storage %d [%d]", i, mtp_storages[i]);
261 mtp_storage = mtp_storages[0];
267 int manager_test_get_object_handles(void)
273 int folder_count = 0;
276 mtp_filetype_e filetype = MTP_FILETYPE_FOLDER;
277 char *filename = NULL;
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);
286 folder_max = (folder_count < TEST_LIST_MAX) ? folder_count : TEST_LIST_MAX;
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));
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);
298 file_max = (file_count < TEST_LIST_MAX) ? file_count : TEST_LIST_MAX;
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));
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);
312 ret = mtp_get_object_handles(mtp_device, mtp_storage, input_int, mtp_object, &mtp_objects, &obj_count);
314 TC_PRT("ret[%d]: total object_num[%d]", ret, obj_count);
316 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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));
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);
332 TC_PRT("selected object id[%d]", mtp_object);
333 TC_PRT("===== Object List - Folder =====");
335 TC_PRT("===== Object List - JPEG =====");
342 int manager_test_delete_object(void)
347 mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
348 char *filename = NULL;
352 TC_PRT("total object_num[%d]", obj_count);
354 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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));
363 if (!test_get_user_int("==> Input Object ID :", &input_int)) {
364 TC_PRT("Invalid Input !!![%d]", input_int);
369 ret = mtp_delete_object(mtp_device, input_int);
370 TC_PRT("ret[%d]: input id[%d]", ret, input_int);
376 int manager_test_get_object(void)
381 mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
382 char *filename = NULL;
383 char filepath[100] = {0,};
387 TC_PRT("total object_num[%d]", obj_count);
389 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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));
398 if (!test_get_user_int("==> Input Object ID :", &input_int)) {
399 TC_PRT("Invalid Input !!![%d]", input_int);
404 snprintf(filepath, 100, "/opt/usr/media/Downloads/JpegObject_%d.jpg", input_int);
406 ret = mtp_get_object(mtp_device, input_int, filepath);
407 TC_PRT("ret[%d]: input id[%d]", ret, input_int);
414 int manager_test_get_thumbnail(void)
419 char input_str[50] = {0, };
420 char filepath[100] = {0,};
421 mtp_filetype_e filetype = MTP_FILETYPE_JPEG;
422 char *filename = NULL;
426 TC_PRT("total object_num[%d]", obj_count);
428 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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));
437 if (!test_get_user_int("==> Input JPEG ID :", &input_int)) {
438 TC_PRT("Invalid Input !!![%d]", input_int);
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);
448 TC_PRT("Invalid Input !!![%s]", input_str);
453 snprintf(filepath, 100, "/opt/usr/media/Downloads/%s_%d.jpg", input_str, input_int);
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);
462 int manager_test_deinitialize(void)
467 ret = mtp_deinitialize();
468 TC_PRT("ret[%d] : deinitialize", ret);
474 int deviceinfo_test_get_manufacturername(void)
480 ret = mtp_deviceinfo_get_manufacturer_name(mtp_device, &name);
481 TC_PRT("ret[%d]: manufacturername[%s]", ret, name);
487 int deviceinfo_test_get_modelname(void)
493 ret = mtp_deviceinfo_get_model_name(mtp_device, &name);
494 TC_PRT("ret[%d]: modelname[%s]", ret, name);
500 int deviceinfo_test_get_serialnumber(void)
506 ret = mtp_deviceinfo_get_serial_number(mtp_device, &name);
507 TC_PRT("ret[%d]: serialnumber[%s]", ret, name);
513 int deviceinfo_test_get_deviceversion(void)
519 ret = mtp_deviceinfo_get_device_version(mtp_device, &name);
520 TC_PRT("ret[%d]: deviceversion[%s]", ret, name);
527 int storageinfo_test_get_description(void)
533 ret = mtp_storageinfo_get_description(mtp_device, mtp_storage, &name);
534 TC_PRT("ret[%d]: description[%s]", ret, name);
540 int storageinfo_test_get_freespace(void)
543 unsigned long long value = 0;
546 ret = mtp_storageinfo_get_free_space(mtp_device, mtp_storage, &value);
547 TC_PRT("ret[%d]: freespace[%llu]", ret, value);
553 int storageinfo_test_get_maxcapacity(void)
556 unsigned long long value = 0;
559 ret = mtp_storageinfo_get_max_capacity(mtp_device, mtp_storage, &value);
560 TC_PRT("ret[%d]: maxcapacity[%llu]", ret, value);
566 int storageinfo_test_get_storagetype(void)
569 mtp_storage_type_e value = 0;
572 ret = mtp_storageinfo_get_storage_type(mtp_device, mtp_storage, &value);
573 TC_PRT("ret[%d]: storagetype[%d]", ret, value);
579 int storageinfo_test_get_volumeidentifier(void)
585 ret = mtp_storageinfo_get_volume_identifier(mtp_device, mtp_storage, &name);
586 TC_PRT("ret[%d]: volumeidentifier[%s]", ret, name);
592 int objectinfo_test_get_association_desc(void)
600 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
611 int objectinfo_test_get_association_type(void)
619 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
630 int objectinfo_test_get_size(void)
638 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
649 int objectinfo_test_get_parent_object_handle(void)
657 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
668 int objectinfo_test_get_storage_id(void)
676 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
687 int objectinfo_test_get_date_created(void)
695 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
706 int objectinfo_test_get_date_modified(void)
714 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
725 int objectinfo_test_get_file_type(void)
729 mtp_filetype_e value = 0;
733 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
744 int objectinfo_test_get_image_bit_depth(void)
752 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
763 int objectinfo_test_get_image_pix_width(void)
771 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
782 int objectinfo_test_get_image_pix_height(void)
790 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
801 int objectinfo_test_get_thumbnail_size(void)
809 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
820 int objectinfo_test_get_thumbnail_file_type(void)
824 mtp_filetype_e value = 0;
828 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
839 int objectinfo_test_get_thumbnail_pix_height(void)
847 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
858 int objectinfo_test_get_thumbnail_pix_width(void)
866 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
877 int objectinfo_test_get_filename(void)
885 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
896 int objectinfo_test_get_keywords(void)
904 list_max = (obj_count < TEST_LIST_MAX) ? obj_count : TEST_LIST_MAX;
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);
915 int application_test_get_image_from_DCIM(void)
919 mtp_filetype_e filetype = MTP_FILETYPE_FOLDER;
921 int object_count = 0;
923 int object_count2 = 0;
924 char filepath[100] = {0,};
925 char *filename = NULL;
927 int input_object_id = 0;
928 int input_object_id2 = 0;
932 TC_PRT("storage_handle : %d", mtp_storage);
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);
940 ret = mtp_get_object_handles(mtp_device, (mtp_storage > 0 ? mtp_storage : 0), input_object_id2, selected_id, &object_list, &object_count);
942 TC_PRT("Total object_num [%d]", object_count);
944 for (i = 0; i < object_count; i++) {
945 TC_PRT("object handle %d", object_list[i]);
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);
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));
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);
960 selected_id = input_object_id;
962 ret = mtp_objectinfo_get_file_name(mtp_device, selected_id, &filename);
963 ret = mtp_objectinfo_get_file_type(mtp_device, selected_id, &filetype);
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));
971 ret = mtp_get_object_handles(mtp_device, (mtp_storage > 0 ? mtp_storage : 0), MTP_FILETYPE_JPEG, selected_id, &object_list2, &object_count2);
973 TC_PRT("Total object_num [%d]", object_count2);
975 for (i = 0; i < object_count2; i++) {
976 TC_PRT("object handle %d", object_list2[i]);
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);
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));
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);
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);
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));
999 if (filetype == MTP_FILETYPE_JPEG) {
1000 snprintf(filepath, 100, "/home/JpegObject_%d.jpg", input_object_id2);
1002 ret = mtp_get_object(mtp_device, input_object_id2, filepath);
1003 TC_PRT("mtp_get_object ret : %d", ret);
1011 int application_test_get_object_handle_using_all(void)
1020 ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_ALL, 0, &file_list, &file_count);
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]);
1030 int application_test_get_object_handle_using_all_image(void)
1038 ret = mtp_get_object_handles(mtp_device, mtp_storage, MTP_FILETYPE_ALL_IMAGE, 0, &file_list, &file_count);
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]);
1048 void __test_mtp_event_cb(mtp_event_e state, int arg, void *user_data)
1052 TC_PRT("state [%d] : %d", state, arg);
1054 if (state == MTP_EVENT_TURNED_OFF) {
1055 ret = mtp_deinitialize();
1056 TC_PRT("ret[%d] : Terminated daemon", ret);
1060 int application_test_event_callback(void)
1066 ret = mtp_set_mtp_event_cb(__test_mtp_event_cb, NULL);
1073 tc_table_t tc_table[] = {
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},
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},
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},
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},
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},
1123 {"Finish", 0x0000, NULL},
1124 {NULL, 0x00ff, NULL},
1127 static void tc_usage_print(void)
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);
1135 printf("Key [%2d] : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
1141 static int test_input_callback(void *data)
1143 long test_id = (long)data;
1144 int ret = MTP_ERROR_NONE;
1146 if ((test_id >= 1) && (test_id <= TEST_CASE_MAX)) {
1147 TC_PRT("test_input_callback test_id : %ld", test_id);
1149 if (tc_table[test_id-1].tc_func != NULL) {
1150 ret = tc_table[test_id-1].tc_func();
1152 if (ret != MTP_ERROR_NONE)
1153 TC_PRT(">>>>> Test Error Returned !!! : %d", ret);
1160 static int test_mtp_terminate(void)
1166 manager_test_deinitialize();
1167 g_main_loop_quit(main_loop);
1172 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1174 char buf[BUFFER_LEN] = {0,};
1178 memset(buf, 0, sizeof(buf));
1179 printf("Event received from stdin\n");
1181 rv = read(0, buf, 100);
1183 if (rv < 0 || buf[0] == '0') {
1184 test_mtp_terminate();
1188 if (*buf == '\n' || *buf == '\r')
1191 test_id = atoi(buf);
1193 test_input_callback((void *)test_id);
1199 int main(int argc, char ** argv)
1203 main_loop = g_main_loop_new(NULL, FALSE);
1204 key_io = g_io_channel_unix_new(0);
1206 printf("Test Thread created...\n");
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);
1211 g_io_channel_unref(key_io);
1212 g_main_loop_unref(main_loop);