diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-09-12 17:18:57 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-02-08 10:29:16 +0100 |
commit | 5e8c5d90db2c55e203c11dbbec91c3e44bcb2023 (patch) | |
tree | 81d89f4749a9e51a26912502317ffc32fac9190f /tests/test_setup_fail.c | |
parent | 05c73e1d3d7693b2ff0f1a5f8c39a6e32c7a2f38 (diff) | |
download | cmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.tar.gz cmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.tar.xz cmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.zip |
tests: Use new cmocka test runner in our tests and examples
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/test_setup_fail.c')
-rw-r--r-- | tests/test_setup_fail.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/test_setup_fail.c b/tests/test_setup_fail.c index 923886c..e3f8df8 100644 --- a/tests/test_setup_fail.c +++ b/tests/test_setup_fail.c @@ -5,11 +5,11 @@ #include <setjmp.h> #include <cmocka.h> -static void setup_fail(void **state) { +static int setup_fail(void **state) { *state = NULL; /* We need to fail in setup */ - assert_non_null(NULL); + return -1; } static void int_test_ignored(void **state) { @@ -17,13 +17,18 @@ static void int_test_ignored(void **state) { assert_non_null(*state); } -static void setup_ok(void **state) { - int *answer = malloc(sizeof(int)); +static int setup_ok(void **state) { + int *answer; - assert_non_null(answer); + answer = malloc(sizeof(int)); + if (answer == NULL) { + return -1; + } *answer = 42; *state = answer; + + return 0; } /* A test case that does check if an int is equal. */ @@ -33,15 +38,17 @@ static void int_test_success(void **state) { assert_int_equal(*answer, 42); } -static void teardown(void **state) { +static int teardown(void **state) { free(*state); + + return 0; } int main(void) { - const UnitTest tests[] = { - unit_test_setup_teardown(int_test_ignored, setup_fail, teardown), - unit_test_setup_teardown(int_test_success, setup_ok, teardown), + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(int_test_ignored, setup_fail, teardown), + cmocka_unit_test_setup_teardown(int_test_success, setup_ok, teardown), }; - return run_tests(tests); + return cmocka_run_group_tests(tests, NULL, NULL); } |