From: Pawel Szewczyk Date: Thu, 1 Oct 2015 11:26:13 +0000 (+0200) Subject: tests: Add test of getting device by vid and pid X-Git-Tag: submit/tizen_common/20160317.155115~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e746c8b5b2a3cf7f01f491d0d89e75a31a4854b;p=platform%2Fcore%2Fapi%2Fusb-host.git tests: Add test of getting device by vid and pid Change-Id: Ieed35e48ae50b00ae8461b52792cb1877873c1fd Signed-off-by: Pawel Szewczyk --- diff --git a/tests/libhusb-test.c b/tests/libhusb-test.c index b2ced9c..dd0d1a5 100644 --- a/tests/libhusb-test.c +++ b/tests/libhusb-test.c @@ -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), };