From: Pawel Szewczyk Date: Thu, 24 Sep 2015 13:41:30 +0000 (+0200) Subject: tests: Add test of getting device list X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46cbe7f16c89bb300a051e9fc72221d256cd0a42;p=platform%2Fcore%2Fapi%2Fusb-host.git tests: Add test of getting device list Change-Id: Ie84a227e75093c78ab7b561a3ff0674e18bf10f4 Signed-off-by: Pawel Szewczyk --- diff --git a/tests/libhusb-test.c b/tests/libhusb-test.c index f8f0ff4..a153917 100644 --- a/tests/libhusb-test.c +++ b/tests/libhusb-test.c @@ -104,6 +104,31 @@ static void test_get_device(void **state) assert_ptr_equal(handle.device, device); } +static void test_get_devices(void **state) +{ + int n = 7, i, ret; + libhusb_context *ctx; + libhusb_device **devs; + + /* TODO init this with some (?) values */ + libusb_device *lusb_devs[7]; + + ctx = (libhusb_context *)(*state); + assert_non_null(ctx); + + will_return(libusb_get_device_list, n); + for (i = 0; i < n; ++i) + will_return(libusb_get_device_list, lusb_devs[i]); + + ret = libhusb_get_devices(ctx, &devs); + + assert_int_equal(ret, n); + for (i = 0; i < n; ++i) + assert_ptr_equal(devs[i]->lusb_dev, lusb_devs[i]); + + libhusb_free_devices(devs, 0); +} + /* Custom macro for defining test with given name and fixed teardown function */ #define HUSB_TEST_CTX(func) \ cmocka_unit_test_setup_teardown(func, setup_libhusb_context, teardown_libhusb_context) @@ -119,6 +144,7 @@ static struct CMUnitTest tests[] = { HUSB_TEST_CTX(test_init), HUSB_TEST_CTX(test_open), HUSB_TEST_NOSETUP(test_get_device), + HUSB_TEST_CTX(test_get_devices), }; diff --git a/tests/libusb-wrap.c b/tests/libusb-wrap.c index f1fb68b..4e92864 100644 --- a/tests/libusb-wrap.c +++ b/tests/libusb-wrap.c @@ -72,12 +72,23 @@ const char * libusb_error_name(int errcode) ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list) { - return 0; + int n, i; + libusb_device **rlist; + + n = mock_type(int); + rlist = calloc(sizeof(libusb_device *), n); + for (i = 0; i < n; ++i) { + rlist[i] = mock_ptr_type(libusb_device *); + } + + *list = rlist; + return n; } void libusb_free_device_list(libusb_device **list, int unref_devices) { + free(list); } libusb_device * libusb_ref_device(libusb_device *dev)