diff --git a/Makefile.am b/Makefile.am index 123f8e4..d4c545a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = libx52 test cli util +SUBDIRS = libx52 cli util libusbx52 test # Extra files that need to be in the distribution EXTRA_DIST = README.md LICENSE diff --git a/configure.ac b/configure.ac index 8e32324..d62eb6e 100644 --- a/configure.ac +++ b/configure.ac @@ -30,8 +30,9 @@ AC_SUBST([X52_CORE_LIB], [../libx52/libx52.la]) AC_CONFIG_FILES([ Makefile libx52/Makefile - test/Makefile + libusbx52/Makefile cli/Makefile util/Makefile + test/Makefile ]) AC_OUTPUT diff --git a/libusbx52/Makefile.am b/libusbx52/Makefile.am new file mode 100644 index 0000000..16d0c19 --- /dev/null +++ b/libusbx52/Makefile.am @@ -0,0 +1,8 @@ +ACLOCAL_AMFLAGS = -I m4 + +# libusb stub library for use by test programs +check_LTLIBRARIES = libusbx52.la + +libusbx52_la_SOURCES = usb_x52_stub.c + +EXTRA_DIST = README.md diff --git a/libusbx52/README.md b/libusbx52/README.md new file mode 100644 index 0000000..749f2ee --- /dev/null +++ b/libusbx52/README.md @@ -0,0 +1,15 @@ +LibUSB mocker library +===================== + +This folder contains a convenience library to mock the API of libusb. This is +intended to be used as an LD_PRELOAD library when used by automated tests to +verify the library without needing actual hardware to verify the tests. + +While a manual test using real hardware is valuable, running some automated +tests in an environment where the hardware is not available is equally valuable, +especially if the source code is changing frequently. + +Note that the API exported by the mocker is limited to the API used by libx52, +as writing a complete USB simulator stack in software is not an easy job, nor is +it necessary for the purposes of this project. + diff --git a/libusbx52/usb_x52_stub.c b/libusbx52/usb_x52_stub.c new file mode 100644 index 0000000..6b7b6bf --- /dev/null +++ b/libusbx52/usb_x52_stub.c @@ -0,0 +1,71 @@ +/* + * LibUSB stub driver for testing the Saitek X52/X52 Pro + * + * Copyright (C) 2017 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include + + +int libusb_init(libusb_context **ctx) +{ + // TODO + return 0; +} + +void libusb_exit(libusb_context *ctx) +{ + // TODO +} + +void libusb_set_debug(libusb_context *ctx, int level) +{ + // TODO +} + +ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list) +{ + // TODO + return 0; +} + +void libusb_free_device_list(libusb_device **list, int unref_devices) +{ + // TODO +} + +int libusb_get_device_descriptor(libusb_device *dev, + struct libusb_device_descriptor *desc) +{ + // TODO + return 0; +} + +int libusb_open(libusb_device *dev, libusb_device_handle **handle) +{ + // TODO + return 0; +} + +void libusb_close(libusb_device_handle *dev_handle) +{ + // TODO +} + +int libusb_control_transfer(libusb_device_handle *dev_handle, + uint8_t request_type, + uint8_t bRequest, + uint16_t wValue, + uint16_t wIndex, + unsigned char *data, + uint16_t wLength, + unsigned int timeout) +{ + // TODO + return 0; +}