tests: Add test of getting device by vid and pid
authorPawel Szewczyk <p.szewczyk@samsung.com>
Thu, 1 Oct 2015 11:26:13 +0000 (13:26 +0200)
committerStanislaw Wadas <s.wadas@samsung.com>
Wed, 2 Dec 2015 12:50:46 +0000 (13:50 +0100)
Change-Id: Ieed35e48ae50b00ae8461b52792cb1877873c1fd
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
tests/libhusb-test.c

index b2ced9c50fa6fbea2c13764ce1756f0570b9672c..dd0d1a5dcceb1a59a4ed53f1f718d4ae33a82625 100644 (file)
@@ -251,6 +251,36 @@ static void test_get_active_config(void **state)
        assert_int_equal(conf, expected);
 }
 
+static void test_open_device_vid_pid(void **state)
+{
+       libhusb_device_handle *handle;
+       libhusb_context *ctx;
+       libusb_device_handle *lusb_dev_handle;
+       libusb_device *lusb_device;
+       uint16_t vid, pid;
+
+       vid = (uint16_t)rand();
+       pid = (uint16_t)rand();
+       lusb_dev_handle = (libusb_device_handle *)rand();
+       lusb_device = (libusb_device *)rand();
+
+       ctx = (libhusb_context *)(*state);
+       assert_non_null(ctx);
+
+       expect_value(libusb_open_device_with_vid_pid, ctx, ctx->lusb_ctx);
+       expect_value(libusb_open_device_with_vid_pid, vendor_id, vid);
+       expect_value(libusb_open_device_with_vid_pid, product_id, pid);
+       will_return(libusb_open_device_with_vid_pid, lusb_dev_handle);
+       will_return(libusb_get_device, lusb_device);
+
+       handle = libhusb_device_open_with_vid_pid(ctx, vid, pid);
+
+       assert_non_null(handle);
+       assert_ptr_equal(handle->lusb_dev_handle, lusb_dev_handle);
+       assert_non_null(handle->device);
+       assert_ptr_equal(handle->device->lusb_dev, lusb_device);
+}
+
 /* Custom macro for defining test with given name and fixed teardown function */
 #define HUSB_TEST(func, setup, teardown) \
        cmocka_unit_test_setup_teardown(func, setup, teardown)
@@ -278,6 +308,7 @@ static struct CMUnitTest tests[] = {
                HUSB_TEST_DEVICE(test_get_address),
                HUSB_TEST_DEVICE(test_get_device_descriptor),
                HUSB_TEST_DEV_HANDLE(test_get_active_config),
+               HUSB_TEST_CTX(test_open_device_vid_pid),
 };