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 "shl_hashtable.h"
48 /* lower address-space is protected from user-allocation, so this is invalid */
49 #define TEST_INVALID_PTR ((void*)0x10)
51 #define TEST_DEFINE_CASE(_name) \
52 static TCase *test_create_case_##_name(void) \
56 tc = tcase_create(#_name); \
58 #define TEST(_name) tcase_add_test(tc, _name);
60 #define TEST_END_CASE \
66 #define TEST_CASE(_name) test_create_case_##_name
68 static inline Suite *test_create_suite(const char *name, ...)
74 s = suite_create(name);
77 while ((fn = va_arg(list, TCase *(*)(void))))
78 suite_add_tcase(s, fn());
84 #define TEST_SUITE(_name, ...) test_create_suite((#_name), ##__VA_ARGS__)
86 static inline int test_run_suite(Suite *s)
91 sr = srunner_create(s);
92 srunner_run_all(sr, CK_NORMAL);
93 ret = srunner_ntests_failed(sr);
99 #define TEST_DEFINE(_suite) \
100 int main(int argc, char **argv) \
102 return test_run_suite(_suite); \
105 #endif /* TEST_COMMON_H */