meson: use get_variable() update to meson 0.51
[mesa-waffle.git] / third_party / cmocka / tests / test_setup_fail.c
blobe3f8df8393a9f2506541a3b61d3944403f358907
1 #define UNIT_TESTING 1
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
8 static int setup_fail(void **state) {
9 *state = NULL;
11 /* We need to fail in setup */
12 return -1;
15 static void int_test_ignored(void **state) {
16 /* should not be called */
17 assert_non_null(*state);
20 static int setup_ok(void **state) {
21 int *answer;
23 answer = malloc(sizeof(int));
24 if (answer == NULL) {
25 return -1;
27 *answer = 42;
29 *state = answer;
31 return 0;
34 /* A test case that does check if an int is equal. */
35 static void int_test_success(void **state) {
36 int *answer = *state;
38 assert_int_equal(*answer, 42);
41 static int teardown(void **state) {
42 free(*state);
44 return 0;
47 int main(void) {
48 const struct CMUnitTest tests[] = {
49 cmocka_unit_test_setup_teardown(int_test_ignored, setup_fail, teardown),
50 cmocka_unit_test_setup_teardown(int_test_success, setup_ok, teardown),
53 return cmocka_run_group_tests(tests, NULL, NULL);