libusb_testlib.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * libusb test library helper functions
  3. * Copyright © 2012 Toby Gray <toby.gray@realvnc.com>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef LIBUSB_TESTLIB_H
  20. #define LIBUSB_TESTLIB_H
  21. #include <config.h>
  22. /** Values returned from a test function to indicate test result */
  23. typedef enum {
  24. /** Indicates that the test ran successfully. */
  25. TEST_STATUS_SUCCESS,
  26. /** Indicates that the test failed one or more test. */
  27. TEST_STATUS_FAILURE,
  28. /** Indicates that an unexpected error occurred. */
  29. TEST_STATUS_ERROR,
  30. /** Indicates that the test can't be run. For example this may be
  31. * due to no suitable device being connected to perform the tests. */
  32. TEST_STATUS_SKIP
  33. } libusb_testlib_result;
  34. /**
  35. * Logs some test information or state
  36. */
  37. void libusb_testlib_logf(const char *fmt, ...) PRINTF_FORMAT(1, 2);
  38. /**
  39. * Structure holding a test description.
  40. */
  41. typedef struct {
  42. /** Human readable name of the test. */
  43. const char *name;
  44. /** The test library will call this function to run the test.
  45. *
  46. * Should return TEST_STATUS_SUCCESS on success or another TEST_STATUS value.
  47. */
  48. libusb_testlib_result (*function)(void);
  49. } libusb_testlib_test;
  50. /**
  51. * Value to use at the end of a test array to indicate the last
  52. * element.
  53. */
  54. #define LIBUSB_NULL_TEST { NULL, NULL }
  55. /**
  56. * Runs the tests provided.
  57. *
  58. * Before running any tests argc and argv will be processed
  59. * to determine the mode of operation.
  60. *
  61. * \param argc The argc from main
  62. * \param argv The argv from main
  63. * \param tests A NULL_TEST terminated array of tests
  64. * \return 0 on success, non-zero on failure
  65. */
  66. int libusb_testlib_run_tests(int argc, char *argv[],
  67. const libusb_testlib_test *tests);
  68. #endif //LIBUSB_TESTLIB_H