[commits] libhid r156 - trunk/test

Martin F. Krafft libhid-discuss@lists.ailab.ch
Sun, 03 Oct 2004 19:29:44 -0600


Author: madduck
Date: Sun Oct  3 19:29:43 2004
New Revision: 156

Modified:
   trunk/test/test_libhid.c
Log:
incorporated return code checking, kudos to Kevin Douglas <douglk gmail.com>


Modified: trunk/test/test_libhid.c
==============================================================================
--- trunk/test/test_libhid.c	(original)
+++ trunk/test/test_libhid.c	Sun Oct  3 19:29:43 2004
@@ -21,26 +21,55 @@
   hid_set_usb_debug(0);
 
   hid_return ret = hid_init();
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_init failed with return code %d\n", ret);
+    return 1;
+  }
 
   HIDInterface* hid = hid_new_HIDInterface();
+  if (hid == 0) {
+    fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
+    return 1;
+  }
+
   char* serial = "01816";
   HIDInterfaceMatcher matcher = { 0x06c2, 0x0038, match_serial_number, (void*)serial, strlen(serial)+1 };
 
   ret = hid_force_open(hid, 0, &matcher, 3);
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
+    return 1;
+  }
 
   ret = hid_write_identification(stdout, hid);
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_write_identification failed with return code %d\n", ret);
+    return 1;
+  }
 
   ret = hid_dump_tree(stdout, hid);
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);
+    return 1;
+  }
 
   int path1[] = { 0xffa00001, 0xffa00002, 0xffa10003 };
   int path2[] = { 0xffa00001, 0xffa00002, 0x0 };
   int path3[] = { 0xffa00001, 0xffa00002, 0xffa10004 };
 
   ret = hid_close(hid);
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_close failed with return code %d\n", ret);
+    return 1;
+  }
 
   hid_delete_HIDInterface(&hid);
 
   ret = hid_cleanup();
+  if (ret != HID_RET_SUCCESS) {
+    fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
+    return 1;
+  }
   
   return 0;
 }