4 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * This header includes all kinds of helpers for testing. It tries to include
29 * everything required and provides simple macros to avoid duplicating code in
30 * each test. We try to keep tests as small as possible and move everything that
31 * might be common here.
33 * We avoid sticking to our usual coding conventions (including headers in
34 * source files, etc. ..) and instead make this the most convenient we can.
46 #include "libtsm_int.h"
47 #include "shl_htable.h"
49 /* lower address-space is protected from user-allocation, so this is invalid */
50 #define TEST_INVALID_PTR ((void*)0x10)
52 #define TEST_DEFINE_CASE(_name) \
53 static TCase *test_create_case_##_name(void) \
57 tc = tcase_create(#_name); \
59 #define TEST(_name) tcase_add_test(tc, _name);
61 #define TEST_END_CASE \
67 #define TEST_CASE(_name) test_create_case_##_name
69 static inline Suite *test_create_suite(const char *name, ...)
75 s = suite_create(name);
78 while ((fn = va_arg(list, TCase *(*)(void))))
79 suite_add_tcase(s, fn());
85 #define TEST_SUITE(_name, ...) test_create_suite((#_name), ##__VA_ARGS__)
87 static inline int test_run_suite(Suite *s)
92 sr = srunner_create(s);
93 srunner_run_all(sr, CK_NORMAL);
94 ret = srunner_ntests_failed(sr);
100 #define TEST_DEFINE(_suite) \
101 int main(int argc, char **argv) \
103 return test_run_suite(_suite); \
106 #endif /* TEST_COMMON_H */