tests: add a better libhusb_close test
authorMichal Bloch <m.bloch@samsung.com>
Tue, 27 Oct 2015 18:32:35 +0000 (19:32 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 29 Oct 2015 15:11:23 +0000 (16:11 +0100)
Since libhusb_device_open_with_vid_pid creates
a device handle with the necessary properties,
i.e. containing a real libusb_device_handle, it
can be used for the libhusb_close test.

This also fixes a memory leak because the handle
was not else deallocated.

The old libhusb_close test (manual allocation
of the libusb_device_handle) stays because it
allows more flexibility as we have control over
what the libusb_device_handle contains, unlike
when using libhusb_device_open_with_vid_pid.

Change-Id: Ic2a77f458023e1e3099ff2e2623fa35730e6bebb
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
tests/libhusb-test.c

index 823b8424b032dd8d46a6be9c47720c8f4bff8a55..a67e45d1a93b73101a0080c922c4f29c3c4267bc 100644 (file)
@@ -342,6 +342,9 @@ static void test_open_device_vid_pid(void **state)
        assert_ptr_equal(handle->lusb_dev_handle, lusb_dev_handle);
        assert_non_null(handle->device);
        assert_ptr_equal(handle->device->lusb_dev, lusb_device);
+
+       expect_value (libusb_close, dev_handle, handle->lusb_dev_handle);
+       libhusb_close(handle);
 }
 
 static void test_set_config(void **state)