tests: add a better libhusb_close test
authorMichal Bloch <m.bloch@samsung.com>
Tue, 27 Oct 2015 18:32:35 +0000 (19:32 +0100)
committerStanislaw Wadas <s.wadas@samsung.com>
Wed, 2 Dec 2015 12:50:46 +0000 (13:50 +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 d9f0afc1c53ff7df175049bb0a767ef8e29b043a..02f16322403f4038f5b572cb9bd0cc11b39d419b 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)