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