Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 1 | /* |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 2 | * libusb test library helper functions |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 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 | |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 20 | #ifndef LIBUSB_TESTLIB_H |
| 21 | #define LIBUSB_TESTLIB_H |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 22 | |
Chris Dickens | f2e551a | 2020-11-27 15:22:29 -0800 | [diff] [blame] | 23 | #include <config.h> |
| 24 | |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 25 | /** Values returned from a test function to indicate test result */ |
| 26 | typedef enum { |
| 27 | /** Indicates that the test ran successfully. */ |
| 28 | TEST_STATUS_SUCCESS, |
| 29 | /** Indicates that the test failed one or more test. */ |
| 30 | TEST_STATUS_FAILURE, |
| 31 | /** Indicates that an unexpected error occurred. */ |
| 32 | TEST_STATUS_ERROR, |
| 33 | /** Indicates that the test can't be run. For example this may be |
Chris Dickens | a016a08 | 2020-09-13 15:30:04 -0700 | [diff] [blame] | 34 | * due to no suitable device being connected to perform the tests. */ |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 35 | TEST_STATUS_SKIP |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 36 | } libusb_testlib_result; |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 39 | * Logs some test information or state |
| 40 | */ |
Chris Dickens | f2e551a | 2020-11-27 15:22:29 -0800 | [diff] [blame] | 41 | void libusb_testlib_logf(const char *fmt, ...) PRINTF_FORMAT(1, 2); |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Structure holding a test description. |
| 45 | */ |
| 46 | typedef struct { |
| 47 | /** Human readable name of the test. */ |
Chris Dickens | a016a08 | 2020-09-13 15:30:04 -0700 | [diff] [blame] | 48 | const char *name; |
| 49 | /** The test library will call this function to run the test. |
| 50 | * |
| 51 | * Should return TEST_STATUS_SUCCESS on success or another TEST_STATUS value. |
| 52 | */ |
| 53 | libusb_testlib_result (*function)(void); |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 54 | } libusb_testlib_test; |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Value to use at the end of a test array to indicate the last |
| 58 | * element. |
| 59 | */ |
Chris Dickens | a016a08 | 2020-09-13 15:30:04 -0700 | [diff] [blame] | 60 | #define LIBUSB_NULL_TEST { NULL, NULL } |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Runs the tests provided. |
| 64 | * |
| 65 | * Before running any tests argc and argv will be processed |
| 66 | * to determine the mode of operation. |
| 67 | * |
| 68 | * \param argc The argc from main |
| 69 | * \param argv The argv from main |
| 70 | * \param tests A NULL_TEST terminated array of tests |
| 71 | * \return 0 on success, non-zero on failure |
| 72 | */ |
Chris Dickens | a016a08 | 2020-09-13 15:30:04 -0700 | [diff] [blame] | 73 | int libusb_testlib_run_tests(int argc, char *argv[], |
| 74 | const libusb_testlib_test *tests); |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 75 | |
hjelmn@cs.unm.edu | 1eff220 | 2014-01-08 23:50:34 +0000 | [diff] [blame] | 76 | #endif //LIBUSB_TESTLIB_H |